diff options
author | victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2003-10-27 09:35:04 +0800 |
---|---|---|
committer | victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2003-10-27 09:35:04 +0800 |
commit | 95c901b5e0ce59134b89bcc31dc52043e0bdafc3 (patch) | |
tree | d631eb450271ccf9f32ce46cd7e268a7dc790e1b /util/cleanpasswd.c | |
parent | efb64bb91a13ea9f7551d8b3ae66620516e086ff (diff) | |
download | pttbbs-95c901b5e0ce59134b89bcc31dc52043e0bdafc3.tar pttbbs-95c901b5e0ce59134b89bcc31dc52043e0bdafc3.tar.gz pttbbs-95c901b5e0ce59134b89bcc31dc52043e0bdafc3.tar.bz2 pttbbs-95c901b5e0ce59134b89bcc31dc52043e0bdafc3.tar.lz pttbbs-95c901b5e0ce59134b89bcc31dc52043e0bdafc3.tar.xz pttbbs-95c901b5e0ce59134b89bcc31dc52043e0bdafc3.tar.zst pttbbs-95c901b5e0ce59134b89bcc31dc52043e0bdafc3.zip |
complete assess
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1264 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'util/cleanpasswd.c')
-rw-r--r-- | util/cleanpasswd.c | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/util/cleanpasswd.c b/util/cleanpasswd.c index 3632ad5e..c5f8a251 100644 --- a/util/cleanpasswd.c +++ b/util/cleanpasswd.c @@ -2,8 +2,6 @@ #define _UTIL_C_ #include "bbs.h" -extern userec_t xuser; - /* 當資料欄位有異動 例如用了舊的欄位 可用這個程式清除舊值 */ int clean_unused_var(userec_t *rec) { @@ -17,10 +15,34 @@ int clean_unused_var(userec_t *rec) int main(int argc, char *argv[]) { - attach_SHM(); - if(passwd_init()) - exit(1); - if (passwd_apply(clean_unused_var) == 0) - printf("ERROR\n"); + int i, fd, fdw; + userec_t user; + + if ((fd = open(BBSHOME"/.PASSWDS", O_RDONLY)) < 0){ + perror("open .PASSWDS error"); + exit(-1); + } + + if ((fdw = open(BBSHOME"/.PASSWDS.new", O_WRONLY | O_TRUNC | O_CREAT, 0600)) < 0){ + perror("open .PASSWDS.new error"); + exit(-1); + } + + for(i = 0; i < MAX_USERS; i++){ + if (read(fd, &user, sizeof(user)) != sizeof(user)) + break; + clean_unused_var(&user); + write(fdw, &user, sizeof(user)); + } + close(fd); + close(fdw); + + if (i != MAX_USERS) + fprintf(stderr, "ERROR\n"); + else{ + fprintf(stderr, "DONE\n"); + system("/bin/mv " BBSHOME "/.PASSWDS " BBSHOME "/.PASSWDS.bak"); + system("/bin/mv " BBSHOME "/.PASSWDS.new " BBSHOME "/.PASSWDS"); + } return 0; } |