summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2008-03-06 20:09:40 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2008-03-06 20:09:40 +0800
commit131a77308798e2c314c7b1a00594e44d7cb3fa3d (patch)
tree53f57bf7cc3f9bf4561e44c6fbf0518d8f3db0b3
parent1ff37fcf607bfc356c60d423ad05fca9d9eab190 (diff)
downloadpttbbs-131a77308798e2c314c7b1a00594e44d7cb3fa3d.tar
pttbbs-131a77308798e2c314c7b1a00594e44d7cb3fa3d.tar.gz
pttbbs-131a77308798e2c314c7b1a00594e44d7cb3fa3d.tar.bz2
pttbbs-131a77308798e2c314c7b1a00594e44d7cb3fa3d.tar.lz
pttbbs-131a77308798e2c314c7b1a00594e44d7cb3fa3d.tar.xz
pttbbs-131a77308798e2c314c7b1a00594e44d7cb3fa3d.tar.zst
pttbbs-131a77308798e2c314c7b1a00594e44d7cb3fa3d.zip
- upgrade: directory for all upgrading scripts/tools/programs
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3967 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--upgrade/Makefile26
-rw-r--r--upgrade/README4
-rw-r--r--upgrade/r2014convert.c63
-rw-r--r--upgrade/r2275_passwd.c146
4 files changed, 239 insertions, 0 deletions
diff --git a/upgrade/Makefile b/upgrade/Makefile
new file mode 100644
index 00000000..d050eba1
--- /dev/null
+++ b/upgrade/Makefile
@@ -0,0 +1,26 @@
+# $Id: Makefile 3673 2007-12-12 01:42:23Z kcwu $
+# Usually you won't build everything for upgrading, so we let you decide what to run.
+
+SRCROOT= ..
+.include "$(SRCROOT)/pttbbs.mk"
+
+CFLAGS+= -DPTTBBS_UTIL
+
+BBSBASE= $(SRCROOT)/include/var.h
+
+UTIL_OBJS= \
+ util_cache.o util_record.o util_passwd.o util_var.o \
+ util_stuff.o util_osdep.o util_args.o util_file.o \
+ util_crypt.o
+
+LIBS+= $(SRCROOT)/src/libbbsutil/libbbsutil.a \
+ $(SRCROOT)/src/libbbs/libbbs.a
+
+all:
+ echo "Usually you won't build everything for upgrading, so we let you decide what to run."
+
+$(SRCROOT)/include/var.h: $(SRCROOT)/mbbsd/var.c
+ cd $(SRCROOT)/mbbsd; $(MAKE) $(SRCROOT)/include/var.h
+
+r2014convert: r2014convert.c
+ $(CCACHE) ${CC} ${CFLAGS} ${LDFLAGS} -o r2014convert r2014convert.c $(LIBS)
diff --git a/upgrade/README b/upgrade/README
new file mode 100644
index 00000000..63be361b
--- /dev/null
+++ b/upgrade/README
@@ -0,0 +1,4 @@
+This file contains upgrading tools/scripts/...
+
+Usually you should stop whole BBS and then run scripts here.
+
diff --git a/upgrade/r2014convert.c b/upgrade/r2014convert.c
new file mode 100644
index 00000000..14de742b
--- /dev/null
+++ b/upgrade/r2014convert.c
@@ -0,0 +1,63 @@
+#include "bbs.h"
+
+int main(){
+ int orig_fd, new_fd;
+ userec_t u;
+ int count = 0;
+
+ orig_fd = open(BBSHOME "/.AngelTrans", O_WRONLY | O_CREAT | O_EXCL, 0600);
+ if (orig_fd == -1) {
+ if (errno == EEXIST) {
+ char c;
+ printf("It seems your .PASSWD file has been transfered, "
+ "do it any way?[y/N] ");
+ fflush(stdout);
+ scanf("%c", &c);
+ if (c != 'y' && c != 'Y')
+ return 0;
+ } else {
+ perror("opening " BBSHOME "/.AngelTrans for marking");
+ return 0;
+ }
+ } else {
+ time4_t t = (time4_t)time(NULL);
+ char* str = ctime4(&t);
+ write(orig_fd, str, strlen(str));
+ }
+
+ orig_fd = open(BBSHOME "/.PASSWDS", O_RDONLY);
+ if( orig_fd < 0 ){
+ perror("opening " BBSHOME "/.PASSWDS for reading");
+ return 1;
+ }
+ printf("Reading from " BBSHOME "/.PASSWDS\n");
+
+ new_fd = open(BBSHOME "/.PASSWDS.NEW", O_WRONLY | O_CREAT | O_TRUNC, 0600);
+ if( new_fd < 0 ){
+ perror("opening " BBSHOME "/.PASSWDS.NEW for writing");
+ return 1;
+ }
+ printf("Writing to " BBSHOME "/.PASSWDS.NEW\n");
+
+ while(read(orig_fd, &u, sizeof(userec_t)) == sizeof(userec_t)){
+ // clear 0x400, 0x800, and 0x3000
+ u.uflag2 &= ~(0x400 | 0x800 | 0x3000);
+ if( u.userlevel & OLD_PERM_NOOUTMAIL )
+ u.uflag2 |= REJ_OUTTAMAIL;
+ u.userlevel &= ~000001000000;
+ bzero(u.myangel, IDLEN + 1);
+ write(new_fd, &u, sizeof(userec_t));
+ ++count;
+ }
+
+ close(orig_fd);
+ close(new_fd);
+ printf("Done, totally %d accounts translated\n", count);
+
+ printf("Moving files....\n");
+ system("mv -i " BBSHOME "/.PASSWDS " BBSHOME "/.PASSWDS.old");
+ system("mv -i " BBSHOME "/.PASSWDS.NEW " BBSHOME "/.PASSWDS");
+ printf("Done, old password file is now at " BBSHOME "/.PASSWDS.old\n");
+
+ return 0;
+}
diff --git a/upgrade/r2275_passwd.c b/upgrade/r2275_passwd.c
new file mode 100644
index 00000000..2361b787
--- /dev/null
+++ b/upgrade/r2275_passwd.c
@@ -0,0 +1,146 @@
+#include "bbs.h"
+
+/* userec_t before revision 2275 */
+typedef struct old_userec_t {
+ char userid[IDLEN + 1];
+ char realname[20];
+ char nickname[24];
+ char passwd[PASSLEN];
+ unsigned char uflag;
+ unsigned int userlevel;
+ unsigned short numlogins;
+ unsigned short numposts;
+ time4_t firstlogin;
+ time4_t lastlogin;
+ char lasthost[16];
+ int money;
+ char remoteuser[3]; /* 保留 目前沒用到的 */
+ char proverb;
+ char email[50];
+ char address[50];
+ char justify[REGLEN + 1];
+ unsigned char month;
+ unsigned char day;
+ unsigned char year;
+ unsigned char sex;
+ unsigned char state;
+ unsigned char pager;
+ unsigned char invisible;
+ unsigned int exmailbox;
+ chicken_t mychicken;
+ time4_t lastsong;
+ unsigned int loginview;
+ unsigned char channel; /* 動態看板 (unused?) */
+ unsigned short vl_count; /* ViolateLaw counter */
+ unsigned short five_win;
+ unsigned short five_lose;
+ unsigned short five_tie;
+ unsigned short chc_win;
+ unsigned short chc_lose;
+ unsigned short chc_tie;
+ int mobile;
+ char mind[4];
+ char ident[11];
+ unsigned int uflag2;
+ unsigned char signature;
+
+ unsigned char goodpost; /* 評價為好文章數 */
+ unsigned char badpost; /* 評價為壞文章數 */
+ unsigned char goodsale; /* 競標 好的評價 */
+ unsigned char badsale; /* 競標 壞的評價 */
+ char myangel[IDLEN+1]; /* 我的小天使 */
+ unsigned short chess_elo_rating; /* 象棋等級分 */
+ unsigned int withme;
+ char pad[48];
+} old_userec_t;
+
+void transform(userec_t *new, old_userec_t *old)
+{
+ new->version = PASSWD_VERSION;
+
+ strlcpy(new->userid, old->userid, IDLEN + 1);
+ strlcpy(new->realname, old->realname, 20);
+ strlcpy(new->nickname, old->nickname, 24);
+ strlcpy(new->passwd, old->passwd, PASSLEN);
+ new->uflag = old->uflag;
+ new->userlevel = old->userlevel;
+ new->numlogins = old->numlogins;
+ new->numposts = old->numposts;
+ new->firstlogin = old->firstlogin;
+ new->lastlogin = old->lastlogin;
+ strlcpy(new->lasthost, old->lasthost, 16);
+ new->money = old->money;
+ strlcpy(new->remoteuser, old->remoteuser, 3);
+ new->proverb = old->proverb;
+ strlcpy(new->email, old->email, 50);
+ strlcpy(new->address, old->address, 50);
+ strlcpy(new->justify, old->justify, REGLEN + 1);
+ new->month = old->month;
+ new->day = old->day;
+ new->year = old->year;
+ new->sex = old->sex;
+ new->state = old->state;
+ new->pager = old->pager;
+ new->invisible = old->invisible;
+ new->exmailbox = old->exmailbox;
+ new->mychicken = old->mychicken;
+ new->lastsong = old->lastsong;
+ new->loginview = old->loginview;
+ new->channel = old->channel;
+ new->vl_count = old->vl_count;
+ new->five_win = old->five_win;
+ new->five_lose = old->five_lose;
+ new->five_tie = old->five_tie;
+ new->chc_win = old->chc_win;
+ new->chc_lose = old->chc_lose;
+ new->chc_tie = old->chc_tie;
+ new->mobile = old->mobile;
+ memcpy(new->mind, old->mind, 4);
+ memset(new->pad0, 0, sizeof(new->pad0)); // ident is not used anymore
+ new->uflag2 = old->uflag2;
+ new->signature = old->signature;
+
+ new->goodpost = old->goodpost;
+ new->badpost = old->badpost;
+ new->goodsale = old->goodsale;
+ new->badsale = old->badsale;
+ strlcpy(new->myangel, old->myangel, IDLEN+1);
+ new->chess_elo_rating = old->chess_elo_rating;
+ new->withme = old->withme;
+ memset(new->pad, 0, sizeof(new->pad));
+}
+
+int main(void)
+{
+ int fd, fdw;
+ userec_t new;
+ old_userec_t old;
+
+ printf("You're going to convert your .PASSWDS\n");
+ printf("The new file will be named .PASSWDS.trans.tmp\n");
+ printf("old size of userec_t is %d, and the new one is %d\n", sizeof(old_userec_t), sizeof(userec_t));
+/*
+ printf("Press any key to continue\n");
+ getchar();
+*/
+
+ 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);
+ write(fdw, &new, sizeof(new));
+ }
+
+ close(fd);
+ close(fdw);
+ return 0;
+}