直接应用两个的struct.h 把改转的转了就行了。
具体可以参见 FB2000目录的 bbssrc/src/util/upgrade
我就是从3.0K UESTC 升级到2000v1219的.
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <time.h>
#include <string.h>
#define STRLEN 80 /* Length of most string data */
#define NAMELEN 40 /* Length of username/realname */
#define IDLEN 12 /* Length of userids */
#define PASSLEN 14 /* Length of encrypted passwd field */
#define PERM_MESSAGE 020000000
struct userec { /* Structure used to huser information in */
char userid[IDLEN+2]; /* PASSFILE */
// char fill[30];
time_t firstlogin;
char lasthost[16];
unsigned int numlogins;
unsigned int numposts;
char flags[2];
char passwd[PASSLEN];
char username[NAMELEN];
char ident[NAMELEN];
char termtype[STRLEN];
unsigned userlevel;
time_t lastlogin;
time_t stay;
char realname[NAMELEN];
char address[STRLEN];
char email[STRLEN];
int signature;
unsigned int userdefine;
time_t notedate;
int noteline;
int notemode;
// int unuse1;/* no use*/
// int unuse3;/* no use*/
};
struct userec2 { /* Structure used to huser information in */
char userid[IDLEN+2]; /* PASSFILE */
time_t firstlogin;
char lasthost[16];
unsigned int numlogins;
unsigned int numposts;
unsigned int medals; /* 奖章数 */
unsigned int money; /* 金钱 */
unsigned int inbank; /* 存款 */
time_t banktime; /* 存入时间 */
char flags[2];
char passwd[PASSLEN];
char username[NAMELEN];
char ident[NAMELEN];
char termtype[16];
char reginfo[STRLEN-16];
unsigned int userlevel;
time_t lastlogin;
time_t lastlogout;/* 最近离线时间 */
time_t stay;
char realname[NAMELEN];
char address[STRLEN];
char email[STRLEN-12];
unsigned int nummails;
time_t lastjustify;
char gender;
unsigned char birthyear;
unsigned char birthmonth;
unsigned char birthday;
int signature;
unsigned int userdefine;
time_t notedate;
int noteline;
};
int main()
{
FILE *fp, *fpout;
struct userec user;
struct userec2 user2;
int readsize, i = 0;
time_t now = time(0);
fp = fopen("PASSWDS", "r");
fpout = fopen("PASSWDS.user2", "w");
if (!fp || !fpout) {
fprintf(stderr, "File error....\n");
exit(EXIT_FAILURE);
}
while (!feof(fp)) {
readsize = fread(&user, sizeof(struct userec), 1, fp);
if (readsize <= 0)
break;
if (ferror(fp)){
perror( "Read error" );
break;
}
if (!user.userid[1])
continue;
memset( &user2, 0, sizeof( user2 ) );
memcpy( user2.userid, user.userid, sizeof(user2.userid));
memcpy( &user2.lasthost, &user.lasthost, sizeof(user2.lasthost));
memcpy( &user2.passwd, &user.passwd, sizeof(user2.passwd));
memcpy( &user2.username, &user.username, sizeof(user2.username));
memcpy( &user2.termtype, &user.termtype, 16);
user2.termtype[15] = '\0';
user2.reginfo[STRLEN-17] = '\0';
memcpy( &user2.realname, &user.realname, sizeof(user2.realname));
memcpy( &user2.address, &user.address, sizeof(user2.address));
memcpy( &user2.email, &user.email, sizeof(user2.email));
user2.email[STRLEN-13] = '\0';
user2.nummails = 0; /* 上站会自动更新信件篇数 */
user2.lastjustify = now;
memcpy( &user2.ident, &user.ident, sizeof(user2.ident));
memcpy( &user2.flags, &user.flags, sizeof(user2.flags));
memcpy( &user2.signature, &user.signature, sizeof(user2.signature));
memcpy( &user2.userdefine, &user.userdefine, sizeof(user2.userdefine));
memcpy( &user2.notedate, &user.notedate, sizeof(user2.notedate));
memcpy( &user2.noteline, &user.noteline, sizeof(user2.noteline));
memcpy( &user2.numlogins, &user.numlogins, sizeof(user2.numlogins));
memcpy( &user2.numposts, &user.numposts, sizeof(user2.numposts));
memcpy( &user2.firstlogin, &user.firstlogin, sizeof(user2.firstlogin));
memcpy( &user2.lastlogin, &user.lastlogin, sizeof(user2.lastlogin));
memcpy( &user2.userlevel, &user.userlevel, sizeof(user2.userlevel));
memcpy( &user2.stay, &user.stay, sizeof(user2.stay));
user2.gender = 'X';
user2.birthyear = 0;
user2.birthmonth = 0;
user2.birthday = 0;
//user2.nummedals = 0;
user2.money = 1000;
//user2.bet = 0;
//user2.dateforbet = now;
user2.lastlogout = now;
user2.userlevel |= PERM_MESSAGE; //都允许发消息 bye Sunner
printf("Processing #%d userid: [%s]\n", i++, user2.userid);
fwrite(&user2, sizeof(struct userec2), 1, fpout);
}
fclose(fp);
fclose(fpout);
}
【 在 chrisduo (风筝) 的大作中提到: 】
: 在REDHAT7.2下升级FB2000版本是1219
: 按照说明升级密码文件.passwd时候,没什么问题
: 但是拷贝覆盖掉时候
: 发现500多个用户只有大概30个用户成功转换了
: 其他的都变成乱七八糟的了,也就是丢失了
: 而且能成功转换的用户每次登陆都必须从新填写一次生日的资料
: 而且注册新用户的时候就吊线
: 请大牛指点啊!!!!!!!
: ~~~~~~~~~~~~~~~~~~~~~~~~
--
修改:turbozv FROM 202.115.22.145
FROM 202.115.22.145