]> code.citadel.org Git - citadel.git/blobdiff - citadel/serv_upgrade.c
mk_module_init.sh now tests to see if echo supports -e and -E
[citadel.git] / citadel / serv_upgrade.c
index 618b5a2dbec60416a37fd5a1c835132cc72c1813..2956e79a088382d9f1ed178b6374b011a348d552 100644 (file)
 #include <limits.h>
 #include "citadel.h"
 #include "server.h"
-#include "sysdep_decls.h"
 #include "citserver.h"
 #include "support.h"
 #include "config.h"
 #include "control.h"
-#include "dynloader.h"
 #include "database.h"
 #include "room_ops.h"
 #include "user_ops.h"
 #include "msgbase.h"
 #include "tools.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) {
-           if (strlen(usbuf.fullname) > 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 */
-               snprintf(vcard, sizeof 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(USERCONFIGROOM, "text/x-vcard",
-                       tempfilename, &newus, 0, 1, CM_SKIP_HOOKS);
-               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 < REV_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 = REV_LEVEL;
-       put_control();
-}
-
-
-
-
-
-
-
+#include "euidindex.h"
 
 
+#include "ctdl_module.h"
 
 
 /* 
  * Back end processing function for cmd_bmbx
  */
-void cmd_bmbx_backend(struct quickroom *qrbuf, void *data) {
+void cmd_bmbx_backend(struct ctdlroom *qrbuf, void *data) {
        static struct RoomProcList *rplist = NULL;
        struct RoomProcList *ptr;
-       struct quickroom qr;
+       struct ctdlroom qr;
 
        /* Lazy programming here.  Call this function as a ForEachRoom backend
         * in order to queue up the room names, or call it with a null room
@@ -175,7 +61,7 @@ void cmd_bmbx_backend(struct quickroom *qrbuf, void *data) {
         */
        if (qrbuf != NULL) {
                ptr = (struct RoomProcList *)
-                       mallok(sizeof (struct RoomProcList));
+                       malloc(sizeof (struct RoomProcList));
                if (ptr == NULL) return;
 
                safestrncpy(ptr->name, qrbuf->QRname, sizeof ptr->name);
@@ -187,61 +73,163 @@ void cmd_bmbx_backend(struct quickroom *qrbuf, void *data) {
        while (rplist != NULL) {
 
                if (lgetroom(&qr, rplist->name) == 0) {
-                       lprintf(9, "Processing <%s>...\n", rplist->name);
+                       lprintf(CTDL_DEBUG, "Processing <%s>...\n", rplist->name);
                        if ( (qr.QRflags & QR_MAILBOX) == 0) {
-                               lprintf(9, "  -- not a mailbox\n");
+                               lprintf(CTDL_DEBUG, "  -- not a mailbox\n");
                        }
                        else {
 
                                qr.QRgen = time(NULL);
-                               lprintf(9, "  -- bumped!\n");
+                               lprintf(CTDL_DEBUG, "  -- fixed!\n");
                        }
                        lputroom(&qr);
                }
 
                ptr = rplist;
                rplist = rplist->next;
-               phree(ptr);
+               free(ptr);
        }
 }
 
 /*
- * quick fix command to bump mailbox generation numbers
+ * quick fix to bump mailbox generation numbers
  */
-void cmd_bmbx(char *argbuf) {
-       int really_do_this  = 0;
+void bump_mailbox_generation_numbers(void) {
+       lprintf(CTDL_WARNING, "Applying security fix to mailbox rooms\n");
+       ForEachRoom(cmd_bmbx_backend, NULL);
+       cmd_bmbx_backend(NULL, NULL);
+       return;
+}
+
 
-       if (CtdlAccessCheck(ac_internal)) return;
-       really_do_this = extract_int(argbuf, 0);
+/* 
+ * Back end processing function for convert_ctdluid_to_minusone()
+ */
+void cbtm_backend(struct ctdluser *usbuf, void *data) {
+       static struct UserProcList *uplist = NULL;
+       struct UserProcList *ptr;
+       struct ctdluser us;
+
+       /* Lazy programming here.  Call this function as a ForEachUser backend
+        * in order to queue up the room names, or call it with a null user
+        * to make it do the processing.
+        */
+       if (usbuf != NULL) {
+               ptr = (struct UserProcList *)
+                       malloc(sizeof (struct UserProcList));
+               if (ptr == NULL) return;
 
-       if (really_do_this != 1) {
-               cprintf("%d You didn't really want to do that.\n", OK);
+               safestrncpy(ptr->user, usbuf->fullname, sizeof ptr->user);
+               ptr->next = uplist;
+               uplist = ptr;
                return;
        }
 
-       ForEachRoom(cmd_bmbx_backend, NULL);
-       cmd_bmbx_backend(NULL, NULL);
+       while (uplist != NULL) {
 
-       cprintf("%d Mailbox generation numbers bumped.\n", OK);
-       return;
+               if (lgetuser(&us, uplist->user) == 0) {
+                       lprintf(CTDL_DEBUG, "Processing <%s>...\n", uplist->user);
+                       if (us.uid == CTDLUID) {
+                               us.uid = (-1);
+                       }
+                       lputuser(&us);
+               }
 
+               ptr = uplist;
+               uplist = uplist->next;
+               free(ptr);
+       }
+}
+
+/*
+ * quick fix to change all CTDLUID users to (-1)
+ */
+void convert_ctdluid_to_minusone(void) {
+       lprintf(CTDL_WARNING, "Applying uid changes\n");
+       ForEachUser(cbtm_backend, NULL);
+       cbtm_backend(NULL, NULL);
+       return;
 }
 
+/*
+ * Do various things to our configuration file
+ */
+void update_config(void) {
+       get_config();
 
+       if (CitControl.version < 606) {
+               config.c_rfc822_strict_from = 0;
+       }
 
+       if (CitControl.version < 609) {
+               config.c_purge_hour = 3;
+       }
 
+       if (CitControl.version < 615) {
+               config.c_ldap_port = 389;
+       }
 
+       if (CitControl.version < 623) {
+               strcpy(config.c_ip_addr, "0.0.0.0");
+       }
 
+       if (CitControl.version < 650) {
+               config.c_enable_fulltext = 0;
+       }
 
+       if (CitControl.version < 652) {
+               config.c_auto_cull = 1;
+       }
 
+       put_config();
+}
 
 
 
 
+void check_server_upgrades(void) {
 
-char *Dynamic_Module_Init(void)
+       get_control();
+       lprintf(CTDL_INFO, "Server-hosted upgrade level is %d.%02d\n",
+               (CitControl.version / 100),
+               (CitControl.version % 100) );
+
+       if (CitControl.version < REV_LEVEL) {
+               lprintf(CTDL_WARNING,
+                       "Server hosted updates need to be processed at "
+                       "this time.  Please wait...\n");
+       }
+       else {
+               return;
+       }
+
+       update_config();
+
+       if ((CitControl.version > 000) && (CitControl.version < 555)) {
+               lprintf(CTDL_EMERG,
+                       "Your data files are from a version of Citadel\n"
+                       "that is too old to be upgraded.  Sorry.\n");
+               exit(EXIT_FAILURE);
+       }
+       if ((CitControl.version > 000) && (CitControl.version < 591)) {
+               bump_mailbox_generation_numbers();
+       }
+       if ((CitControl.version > 000) && (CitControl.version < 608)) {
+               convert_ctdluid_to_minusone();
+       }
+       if ((CitControl.version > 000) && (CitControl.version < 659)) {
+               rebuild_euid_index();
+       }
+
+       CitControl.version = REV_LEVEL;
+       put_control();
+}
+
+
+CTDL_MODULE_INIT(upgrade)
 {
        check_server_upgrades();
-       CtdlRegisterProtoHook(cmd_bmbx, "BMBX", "Bump mailboxes");
+
+       /* return our Subversion id for the Log */
        return "$Id$";
 }