]> code.citadel.org Git - citadel.git/commitdiff
* Added serv_upgrade.h to automagically convert pre-5.55 format user records
authorArt Cancro <ajc@citadel.org>
Sun, 3 Oct 1999 21:48:21 +0000 (21:48 +0000)
committerArt Cancro <ajc@citadel.org>
Sun, 3 Oct 1999 21:48:21 +0000 (21:48 +0000)
  to 5.55 format user records and generate vCards.

citadel/ChangeLog
citadel/Makefile.in
citadel/citadel.h
citadel/serv_upgrade.c [new file with mode: 0644]
citadel/serv_upgrade.h [new file with mode: 0644]
citadel/serv_upgrade.sh [deleted file]
citadel/sysdep.c
citadel/user_ops.c

index d69178f3721cedfd620173eb0830a9029acf681d..caa7b8dd5e453588db77fcd809cf48b070213594 100644 (file)
@@ -1,4 +1,8 @@
 $Log$
+Revision 1.376  1999/10/03 21:48:21  ajc
+* Added serv_upgrade.h to automagically convert pre-5.55 format user records
+  to 5.55 format user records and generate vCards.
+
 Revision 1.375  1999/09/29 21:13:17  ajc
 * CtdlWriteObject() can now store objects in personal rooms for any specified
   user -- rather than only the current user or non-personal rooms.
@@ -1287,3 +1291,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
        * Initial CVS import 
+
index 4ca56c8ca398fd0eb2024f9d4b839c8f038285e9..06705a1b39018181d1753a4d1ff41e59f098baeb 100644 (file)
@@ -25,6 +25,7 @@ SO=@SO@
 CLIENT_TARGETS=citadel$(EXEEXT) whobbs$(EXEEXT)
 SERVER_TARGETS=citserver setup $(CHKPWD)
 SERV_MODULES=modules/serv_chat$(SO) modules/serv_vcard$(SO) \
+       modules/serv_upgrade$(SO) \
        modules/serv_expire$(SO) modules/serv_icq$(SO)
 UTIL_TARGETS=aidepost netmailer netproc netsetup msgform readlog rcit \
        stats citmail netpoll mailinglist userlist sendcommand \
@@ -68,7 +69,7 @@ SOURCES=aidepost.c citadel.c citmail.c citserver.c client_chat.c commands.c \
        serv_info.c serv_test.c setup.c snprintf.c stats.c serv_vcard.c \
        support.c sysdep.c tools.c user_ops.c userlist.c serv_expire.c \
        whobbs.c sendcommand.c mime_parser.c base64.c qpdecode.c getutline.c \
-       auth.c chkpwd.c client_icq.c html.c vcard.c
+       auth.c chkpwd.c client_icq.c html.c vcard.c serv_upgrade.c
 
 DEP_FILES=$(SOURCES:.c=.d)
 
@@ -139,6 +140,12 @@ modules/serv_icq.so: serv_icq.mo
 modules/serv_icq.mo: serv_icq.mo
        ln -f serv_icq.mo modules
 
+modules/serv_upgrade.so: serv_upgrade.mo
+       $(LINK_SHARED) -o modules/serv_upgrade.so serv_upgrade.mo
+
+modules/serv_upgrade.mo: serv_upgrade.mo
+       ln -f serv_upgrade.mo modules
+
 modules/serv_vcard.so: serv_vcard.mo vcard.mo
        $(LINK_SHARED) -o modules/serv_vcard.so serv_vcard.mo vcard.mo
 
index 1f8f4ebb99bc95aff5b5685b16e98b902407b43a..268243462a9ef6d151197e543cbf9a5d4178a595 100644 (file)
@@ -8,8 +8,8 @@
 #include "sysdep.h"
 #include "sysconfig.h"
 #include "ipcdef.h"
-#define CITADEL        "Citadel/UX 5.53"
-#define REV_LEVEL 553
+#define CITADEL        "Citadel/UX 5.55"
+#define REV_LEVEL 555
 #define SERVER_TYPE 0  /* zero for stock Citadel/UX; other developers please
                           obtain SERVER_TYPE codes for your implementations */
 
@@ -90,26 +90,21 @@ struct config {
 #define RESTRICT_INTERNET      config.c_restrict
 
 /* Defines the actual user record */
 struct usersupp {                      /* User record                      */
-       int USuid;                      /* userid (==BBSUID for bbs only)   */
-       char password[20];              /* password (for BBS-only users)    */
+       int version;                    /* Cit vers. which created this rec */
+       uid_t uid;                      /* Associate with a unix account?   */
+       char password[32];              /* password (for BBS-only users)    */
        unsigned flags;                 /* See US_ flags below              */
-       int timescalled;                /* Total number of logins           */
-       int posted;                     /* Number of messages posted (ever) */
-       char fullname[26];              /* Name for Citadel messages & mail */
-       char axlevel;                   /* Access level                     */
-       CIT_UBYTE USscreenwidth;        /* Screen width (for textmode users)*/
-       CIT_UBYTE USscreenheight;       /* Screen height(for textmode users)*/
+       long timescalled;               /* Total number of logins           */
+       long posted;                    /* Number of messages posted (ever) */
+       CIT_UBYTE axlevel;              /* Access level                     */
        long usernum;                   /* User number (never recycled)     */
        time_t lastcall;                /* Last time the user called        */
-       char USname[30];                /* Real name (i.e. not a handle)    */
-       char USaddr[25];                /* Street address                   */
-       char UScity[15];                /* Municipality                     */
-       char USstate[3];                /* State or province                */
-       char USzip[10];                 /* ZIP code                         */
-       char USphone[11];               /* Voice telephone number           */
-       char USemail[32];               /* E-mail address (elsewhere)       */
        int USuserpurge;                /* Purge time (in days) for user    */
+       char fullname[64];              /* Name for Citadel messages & mail */
+       CIT_UBYTE USscreenwidth;        /* Screen width (for textmode users)*/
+       CIT_UBYTE USscreenheight;       /* Screen height(for textmode users)*/
        };
 
 
@@ -121,6 +116,7 @@ struct CitControl {
        unsigned MMflags;               /* Global system flags              */
        long MMnextuser;                /* highest user number on system    */
        long MMnextroom;                /* highest room number on system    */
+       int version;                    /* Server-hosted upgrade level      */
        };
 
 /* Bits which may appear in CitControl.MMflags.  Note that these don't
@@ -149,12 +145,11 @@ struct quickroom {
        };
 
 
-/* Private rooms are always flagged with QR_PRIVATE. If neither QR_PASSWORDED
- * or QR_GUESSNAME is set, then it is invitation-only. Passworded rooms are
+/* Private rooms are always flagged with QR_PRIVATE.  If neither QR_PASSWORDED
+ * or QR_GUESSNAME is set, then it is invitation-only.  Passworded rooms are
  * flagged with both QR_PRIVATE and QR_PASSWORDED while guess-name rooms are
- * flagged with both QR_PRIVATE and QR_GUESSNAME. DO NOT set all three flags.
- *
- ****************************************************************************/
+ * flagged with both QR_PRIVATE and QR_GUESSNAME.  NEVER set all three flags.
+ */
 
 /*
  * Events which might show up in the Citadel Log
@@ -177,7 +172,7 @@ struct quickroom {
 #define MES_ERROR      (-1)    /* Can't send message due to bad address   */
 #define MES_LOCAL      0       /* Local message, do no network processing */
 #define MES_INTERNET   1       /* Convert msg and send as Internet mail   */
-#define MES_BINARY     2       /* Process recipient and send via C/UX net */
+#define MES_BINARY     2       /* Process recipient and send via Cit net  */
 
 /****************************************************************************/
 
diff --git a/citadel/serv_upgrade.c b/citadel/serv_upgrade.c
new file mode 100644 (file)
index 0000000..cf24533
--- /dev/null
@@ -0,0 +1,148 @@
+/* $Id$ */
+#include "sysdep.h"
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <pwd.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/wait.h>
+#include <string.h>
+#include <limits.h>
+#ifdef HAVE_PTHREAD_H
+#include <pthread.h>
+#endif
+#include "citadel.h"
+#include "server.h"
+#include <syslog.h>
+#include <time.h>
+#include "sysdep_decls.h"
+#include "citserver.h"
+#include "support.h"
+#include "config.h"
+#include "control.h"
+#include "dynloader.h"
+#include "database.h"
+#include "user_ops.h"
+#include "msgbase.h"
+#include "serv_upgrade.h"
+
+void do_pre555_usersupp_upgrade(void) {
+        struct pre555usersupp usbuf;
+       struct usersupp newus;
+        struct cdbdata *cdbus;
+       char tempfilename[PATH_MAX];
+       FILE *fp, *tp;
+       static char vcard[1024];
+
+       lprintf(5, "Upgrading user file\n");
+       fp = tmpfile();
+       if (fp == NULL) {
+               lprintf(1, "%s\n", strerror(errno));
+               exit(errno);
+       }
+       strcpy(tempfilename, tmpnam(NULL));
+
+       /* First, back out all old version records to a flat file */
+        cdb_rewind(CDB_USERSUPP);
+        while(cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
+                memset(&usbuf, 0, sizeof(struct pre555usersupp));
+                memcpy(&usbuf, cdbus->ptr,
+                               ( (cdbus->len > sizeof(struct pre555usersupp)) ?
+                               sizeof(struct pre555usersupp) : cdbus->len) );
+                cdb_free(cdbus);
+               fwrite(&usbuf, sizeof(struct pre555usersupp), 1, fp);
+       }
+
+       /* ...and overwrite the records with new format records */
+       rewind(fp);
+       while (fread(&usbuf, sizeof(struct pre555usersupp), 1, fp) > 0) {
+               lprintf(9, "Upgrading <%s>\n", usbuf.fullname);
+               memset(&newus, 0, sizeof(struct usersupp));
+
+               newus.uid = usbuf.USuid;
+               strcpy(newus.password, usbuf.password);
+               newus.flags = usbuf.flags;
+               newus.timescalled = (long) usbuf.timescalled;
+               newus.posted = (long) usbuf.posted;
+               newus.axlevel = (CIT_UBYTE) usbuf.axlevel;
+               newus.usernum = (long) usbuf.usernum;
+               newus.lastcall = (long) usbuf.lastcall;
+               newus.USuserpurge = (int) usbuf.USuserpurge;
+               strcpy(newus.fullname, usbuf.fullname);
+               newus.USscreenwidth = (CIT_UBYTE) usbuf.USscreenwidth;
+               newus.USscreenheight = (CIT_UBYTE) usbuf.USscreenheight;
+
+               putuser(&newus);
+
+               /* write the vcard */
+               sprintf(vcard,
+                       "Content-type: text/x-vcard\n\n"
+                       "begin:vcard\n"
+                       "n:%s\n"
+                       "tel;home:%s\n"
+                       "email;internet:%s\n"
+                       "adr:;;%s;%s;%s;%s;USA\n"
+                       "end:vcard\n",
+                       usbuf.USname,
+                       usbuf.USphone,
+                       usbuf.USemail,
+                       usbuf.USaddr,
+                       usbuf.UScity,
+                       usbuf.USstate,
+                       usbuf.USzip);
+
+               tp = fopen(tempfilename, "w");
+               fwrite(vcard, strlen(vcard)+1, 1, tp);
+               fclose(tp);
+
+               CtdlWriteObject(CONFIGROOM, "text/x-vcard",
+                       tempfilename, &newus, 0, 1);    
+               unlink(tempfilename);
+
+       }
+
+       fclose(fp);     /* this file deletes automatically */
+}
+
+
+
+
+
+
+
+
+void check_server_upgrades(void) {
+
+       get_control();
+       lprintf(5, "Server-hosted upgrade level is %d.%02d\n",
+               (CitControl.version / 100),
+               (CitControl.version % 100) );
+
+       if (CitControl.version < config.c_setup_level) {
+               lprintf(5, "Server hosted updates need to be processed at "
+                               "this time.  Please wait...\n");
+       }
+       else {
+               return;
+       }
+
+
+       if (CitControl.version < 555) do_pre555_usersupp_upgrade();
+
+
+       CitControl.version = config.c_setup_level;
+       put_control();
+}
+
+
+
+
+char *Dynamic_Module_Init(void)
+{
+       check_server_upgrades();
+       return "$Id$";
+}
diff --git a/citadel/serv_upgrade.h b/citadel/serv_upgrade.h
new file mode 100644 (file)
index 0000000..06eb854
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Format of a usersupp record prior to version 5.55
+ */
+struct pre555usersupp {                        /* User record                      */
+       int USuid;                      /* userid (==BBSUID for bbs only)   */
+       char password[20];              /* password (for BBS-only users)    */
+       unsigned flags;                 /* See US_ flags below              */
+       int timescalled;                /* Total number of logins           */
+       int posted;                     /* Number of messages posted (ever) */
+       char fullname[26];              /* Name for Citadel messages & mail */
+       char axlevel;                   /* Access level                     */
+       CIT_UBYTE USscreenwidth;        /* Screen width (for textmode users)*/
+       CIT_UBYTE USscreenheight;       /* Screen height(for textmode users)*/
+       long usernum;                   /* User number (never recycled)     */
+       time_t lastcall;                /* Last time the user called        */
+       char USname[30];                /*                                  */
+       char USaddr[25];                /*                                  */
+       char UScity[15];                /*                                  */
+       char USstate[3];                /*                                  */
+       char USzip[10];                 /*                                  */
+       char USphone[11];               /*                                  */
+       char USemail[32];               /*                                  */
+       int USuserpurge;                /* Purge time (in days) for user    */
+};
diff --git a/citadel/serv_upgrade.sh b/citadel/serv_upgrade.sh
deleted file mode 100755 (executable)
index 9197386..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-#/bin/sh
-#
-# Please don't add this to the Makefile
-#
-cc -O2 -Wall -D_REENTRANT -fPIC -c serv_upgrade.c
-cc -shared -o modules/serv_upgrade.so serv_upgrade.o
index 5e83c9c513d68bc14774e8e6457096e5588cec31..1e8a00fabded2bd99dacd9700c2bf70b83376205 100644 (file)
@@ -907,6 +907,14 @@ int main(int argc, char **argv)
                        }
                }
 
+       /*
+        * Do non system dependent startup functions.
+        */
+       master_startup();
+
+       /*
+        * Load any server-side modules (plugins) available here.
+        */
        lprintf(7, "Initializing loadable modules\n");
        if ((moddir = malloc(strlen(bbs_home_directory) + 9)) != NULL) {
                sprintf(moddir, "%s/modules", bbs_home_directory);
@@ -915,11 +923,6 @@ int main(int argc, char **argv)
                }
        lprintf(9, "Modules done initializing.\n");
 
-       /*
-        * Do non system dependent startup functions.
-        */
-       master_startup();
-
        /* 
         * Endless loop.  Listen on the master socket.  When a connection
         * comes in, create a socket, a context, and a thread.
index dcdbbe555bea7fdd3ecf1cc767dd51e6438ac037..608d4a584cb2dfa5f7771a2a66a20edca76fd585 100644 (file)
@@ -95,6 +95,7 @@ void putuser(struct usersupp *usbuf)
                }
        lowercase_name[sizeof(lowercase_name)-1] = 0;
 
+       usbuf->version = config.c_setup_level;
        cdb_store(CDB_USERSUPP,
                lowercase_name, strlen(lowercase_name),
                usbuf, sizeof(struct usersupp));
@@ -424,14 +425,14 @@ void cmd_pass(char *buf)
                }
 
        code = (-1);
-       if (CC->usersupp.USuid == BBSUID) {
+       if (CC->usersupp.uid == BBSUID) {
                strproc(password);
                strproc(CC->usersupp.password);
                code = strcasecmp(CC->usersupp.password,password);
                }
 #ifdef ENABLE_AUTOLOGIN
        else {
-               if (validpw(CC->usersupp.USuid, password)) {
+               if (validpw(CC->usersupp.uid, password)) {
                        code = 0;
                        lgetuser(&CC->usersupp, CC->curr_user);
                        safestrncpy(CC->usersupp.password, password,
@@ -536,10 +537,10 @@ int create_user(char *newusername)
                for (a=0; a<strlen(username); ++a) {
                        if (username[a] == ',') username[a] = 0;
                        }
-               CC->usersupp.USuid = p->pw_uid;
+               CC->usersupp.uid = p->pw_uid;
                }
        else {
-               CC->usersupp.USuid = BBSUID;
+               CC->usersupp.uid = BBSUID;
                }
 
        if (!getuser(&usbuf,username)) {
@@ -561,12 +562,6 @@ int create_user(char *newusername)
        CC->usersupp.USscreenwidth = 80;
        CC->usersupp.USscreenheight = 24;
        time(&CC->usersupp.lastcall);
-       strcpy(CC->usersupp.USname, "");
-       strcpy(CC->usersupp.USaddr, "");
-       strcpy(CC->usersupp.UScity, "");
-       strcpy(CC->usersupp.USstate, "");
-       strcpy(CC->usersupp.USzip, "");
-       strcpy(CC->usersupp.USphone, "");
 
        /* fetch a new user number */
        CC->usersupp.usernum = get_new_user_number();
@@ -658,7 +653,7 @@ void cmd_setp(char *new_pw)
                cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
                return;
                }
-       if (CC->usersupp.USuid != BBSUID) {
+       if (CC->usersupp.uid != BBSUID) {
                cprintf("%d Not allowed.  Use the 'passwd' command.\n",ERROR);
                return;
                }