1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
/* $Id: toplazyBM.c 1096 2003-08-15 06:13:29Z victor $ */
#define _UTIL_C_
#include "bbs.h"
/* 當資料欄位有異動 例如用了舊的欄位 可用這個程式清除舊值 */
int clean_unused_var(userec_t *rec)
{
rec->goodpost = 0;
rec->badpost = 0;
rec->goodsale = 0;
rec->badsale = 0;
memset(rec->pad, 0, sizeof(rec->pad));
return 0;
}
int main(int argc, char *argv[])
{
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;
}
|