4 * Transparently handle the upgrading of server data formats.
6 * Copyright (c) 1987-2009 by the citadel.org team
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include <sys/types.h>
33 #if TIME_WITH_SYS_TIME
34 # include <sys/time.h>
38 # include <sys/time.h>
47 #include <libcitadel.h>
50 #include "citserver.h"
58 #include "serv_upgrade.h"
59 #include "euidindex.h"
62 #include "ctdl_module.h"
67 * Fix up the name for Citadel user 0 and try to remove any extra users with number 0
69 void fix_sys_user_name(void)
71 struct ctdluser usbuf;
72 char usernamekey[USERNAME_SIZE];
74 /** If we have a user called Citadel rename them to SYS_Citadel */
75 if (getuser(&usbuf, "Citadel") == 0)
77 rename_user("Citadel", "SYS_Citadel");
80 while (getuserbynumber(&usbuf, 0) == 0)
82 /* delete user with number 0 and no name */
83 if (IsEmptyStr(usbuf.fullname))
84 cdb_delete(CDB_USERS, "", 0);
86 { /* temporarily set this user to -1 */
92 /** Make sure user SYS_* is user 0 */
93 while (getuserbynumber(&usbuf, -1) == 0)
95 if (strncmp(usbuf.fullname, "SYS_", 4))
96 { /** Delete any user 0 that doesn't start with SYS_ */
97 makeuserkey(usernamekey, usbuf.fullname);
98 cdb_delete(CDB_USERS, usernamekey, strlen(usernamekey));
110 * Back end processing function for cmd_bmbx
112 void cmd_bmbx_backend(struct ctdlroom *qrbuf, void *data) {
113 static struct RoomProcList *rplist = NULL;
114 struct RoomProcList *ptr;
117 /* Lazy programming here. Call this function as a ForEachRoom backend
118 * in order to queue up the room names, or call it with a null room
119 * to make it do the processing.
122 ptr = (struct RoomProcList *)
123 malloc(sizeof (struct RoomProcList));
124 if (ptr == NULL) return;
126 safestrncpy(ptr->name, qrbuf->QRname, sizeof ptr->name);
132 while (rplist != NULL) {
134 if (lgetroom(&qr, rplist->name) == 0) {
135 CtdlLogPrintf(CTDL_DEBUG, "Processing <%s>...\n", rplist->name);
136 if ( (qr.QRflags & QR_MAILBOX) == 0) {
137 CtdlLogPrintf(CTDL_DEBUG, " -- not a mailbox\n");
141 qr.QRgen = time(NULL);
142 CtdlLogPrintf(CTDL_DEBUG, " -- fixed!\n");
148 rplist = rplist->next;
154 * quick fix to bump mailbox generation numbers
156 void bump_mailbox_generation_numbers(void) {
157 CtdlLogPrintf(CTDL_WARNING, "Applying security fix to mailbox rooms\n");
158 ForEachRoom(cmd_bmbx_backend, NULL);
159 cmd_bmbx_backend(NULL, NULL);
165 * Back end processing function for convert_ctdluid_to_minusone()
167 void cbtm_backend(struct ctdluser *usbuf, void *data) {
168 static struct UserProcList *uplist = NULL;
169 struct UserProcList *ptr;
172 /* Lazy programming here. Call this function as a ForEachUser backend
173 * in order to queue up the room names, or call it with a null user
174 * to make it do the processing.
177 ptr = (struct UserProcList *)
178 malloc(sizeof (struct UserProcList));
179 if (ptr == NULL) return;
181 safestrncpy(ptr->user, usbuf->fullname, sizeof ptr->user);
187 while (uplist != NULL) {
189 if (lgetuser(&us, uplist->user) == 0) {
190 CtdlLogPrintf(CTDL_DEBUG, "Processing <%s>...\n", uplist->user);
191 if (us.uid == CTDLUID) {
198 uplist = uplist->next;
204 * quick fix to change all CTDLUID users to (-1)
206 void convert_ctdluid_to_minusone(void) {
207 CtdlLogPrintf(CTDL_WARNING, "Applying uid changes\n");
208 ForEachUser(cbtm_backend, NULL);
209 cbtm_backend(NULL, NULL);
215 * Attempt to guess the name of the time zone currently in use
216 * on the underlying host system.
218 void guess_time_zone(void) {
222 fp = popen(file_guesstimezone, "r");
224 if (fgets(buf, sizeof buf, fp) && (strlen(buf) > 2)) {
225 buf[strlen(buf)-1] = 0;
226 safestrncpy(config.c_default_cal_zone, buf, sizeof config.c_default_cal_zone);
227 CtdlLogPrintf(CTDL_INFO, "Configuring timezone: %s\n", config.c_default_cal_zone);
235 * Do various things to our configuration file
237 void update_config(void) {
240 if (CitControl.version < 606) {
241 config.c_rfc822_strict_from = 0;
244 if (CitControl.version < 609) {
245 config.c_purge_hour = 3;
248 if (CitControl.version < 615) {
249 config.c_ldap_port = 389;
252 if (CitControl.version < 623) {
253 strcpy(config.c_ip_addr, "0.0.0.0");
256 if (CitControl.version < 650) {
257 config.c_enable_fulltext = 0;
260 if (CitControl.version < 652) {
261 config.c_auto_cull = 1;
264 if (CitControl.version < 725) {
265 config.c_xmpp_c2s_port = 5222;
266 config.c_xmpp_s2s_port = 5269;
269 /* Erase LDAP config that might be left over from the old connector
270 * which served a different purpose.
272 if (CitControl.version < 760) {
273 strcpy(config.c_ldap_host, "");
274 config.c_ldap_port = 389;
275 strcpy(config.c_ldap_base_dn, "");
276 strcpy(config.c_ldap_bind_dn, "");
277 strcpy(config.c_ldap_bind_pw, "");
280 if (IsEmptyStr(config.c_default_cal_zone)) {
290 void check_server_upgrades(void) {
293 CtdlLogPrintf(CTDL_INFO, "Server-hosted upgrade level is %d.%02d\n",
294 (CitControl.version / 100),
295 (CitControl.version % 100) );
297 if (CitControl.version < REV_LEVEL) {
298 CtdlLogPrintf(CTDL_WARNING,
299 "Server hosted updates need to be processed at "
300 "this time. Please wait...\n");
308 if ((CitControl.version > 000) && (CitControl.version < 555)) {
309 CtdlLogPrintf(CTDL_EMERG,
310 "Your data files are from a version of Citadel\n"
311 "that is too old to be upgraded. Sorry.\n");
314 if ((CitControl.version > 000) && (CitControl.version < 591)) {
315 bump_mailbox_generation_numbers();
317 if ((CitControl.version > 000) && (CitControl.version < 608)) {
318 convert_ctdluid_to_minusone();
320 if ((CitControl.version > 000) && (CitControl.version < 659)) {
321 rebuild_euid_index();
323 if (CitControl.version < 735) {
326 if (CitControl.version < 736) {
327 rebuild_usersbynumber();
329 CitControl.version = REV_LEVEL;
334 CTDL_MODULE_UPGRADE(upgrade)
336 check_server_upgrades();
338 /* return our Subversion id for the Log */