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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
#define _UTIL_C_
#include "bbs.h"
#include <time.h>
// old uflag2 bits
#ifndef OUF2_FAVNOHILIGHT
#define OUF2_FAVNOHILIGHT 0x00000010 /* false if hilight favorite */
#define OUF2_FAVNEW_FLAG 0x00000020 /* true if add new board into one's fav */
#define OUF2_FOREIGN 0x00000100 /* true if a foreign */
#define OUF2_LIVERIGHT 0x00000200 /* true if get "liveright" already */
#define OUF2_REJ_OUTTAMAIL 0x00000400 /* true if don't accept outside mails */
#endif
const unsigned int ufmap_from[] = {
OUF2_FAVNOHILIGHT,
OUF2_FAVNEW_FLAG,
OUF2_FOREIGN,
OUF2_LIVERIGHT,
OUF2_REJ_OUTTAMAIL,
0,
};
const unsigned int ufmap_to[] = {
UF_FAV_NOHILIGHT,
UF_FAV_ADDNEW,
UF_FOREIGN,
UF_LIVERIGHT,
UF_REJ_OUTTAMAIL,
0,
};
const char *ufmap_names [] = {
"FAV_NOHILIGHT",
"FAV_ADDNEW",
"FOREIGN",
"LIVERIGHT",
"REJ_OUTTAMAIL",
};
int transform(userec_t *new, userec_t *old, int i)
{
userec_t *u = new;
int dirty = 0;
memcpy(new, old, sizeof(userec_t));
if (!u->userid[0])
return 0;
for (i = 0; ufmap_from[i]; i++)
{
int ov = (u->deprecated_uflag2 & ufmap_from[i]) ? 1 : 0,
nv = (u->uflag & ufmap_to[i]) ? 1 : 0;
if (ov == nv)
continue;
if (dirty++ == 0) printf("%-13s: %08X => [", u->userid, u->uflag);
u->uflag &= ~(ufmap_to[i]);
if (u->deprecated_uflag2 & ufmap_from[i])
{
u->uflag |= ufmap_to[i];
printf("%s ", ufmap_names[i]);
}
}
if (!dirty)
return 0;
printf("] => %08X\n", u->uflag);
// force convert!
// passwd_update(n+1, u);
return 0;
}
int main(void)
{
int fd, fdw;
userec_t new;
userec_t old;
int i = 0;
printf("sizeof(userec_t)=%u\n", (unsigned int)sizeof(userec_t));
printf("You're going to convert your .PASSWDS\n");
printf("The new file will be named .PASSWDS.trans.tmp\n");
if (chdir(BBSHOME) < 0) {
perror("chdir");
exit(-1);
}
if ((fd = open(FN_PASSWD, O_RDONLY)) < 0 ||
(fdw = open(FN_PASSWD".trans.tmp", O_WRONLY | O_CREAT | O_TRUNC, 0600)) < 0 ) {
perror("open");
exit(-1);
}
while (read(fd, &old, sizeof(old)) > 0) {
transform(&new, &old, ++i);
write(fdw, &new, sizeof(new));
}
close(fd);
close(fdw);
// printf("total %d records converted.\n", accs);
return 0;
}
|