* guesses about what kind of data format changes need to be applied, and
* we apply them transparently.
*
- * Copyright (c) 1987-2019 by the citadel.org team
+ * Copyright (c) 1987-2020 by the citadel.org team
*
* This program is open source software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 3.
#include <pwd.h>
#include <errno.h>
#include <sys/types.h>
-
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-# if HAVE_SYS_TIME_H
-# include <sys/time.h>
-# else
-# include <time.h>
-# endif
-#endif
-
+#include <time.h>
#include <sys/wait.h>
#include <string.h>
#include <limits.h>
int oldver = 0;
/*
- * Fix up the name for Citadel user 0 and try to remove any extra users with number 0
+ * Try to remove any extra users with number 0
*/
void fix_sys_user_name(void)
{
struct ctdluser usbuf;
char usernamekey[USERNAME_SIZE];
- /** If we have a user called Citadel rename them to SYS_Citadel */
- if (CtdlGetUser(&usbuf, "Citadel") == 0)
- {
- rename_user("Citadel", "SYS_Citadel");
- }
-
- while (CtdlGetUserByNumber(&usbuf, 0) == 0)
- {
+ while (CtdlGetUserByNumber(&usbuf, 0) == 0) {
/* delete user with number 0 and no name */
if (IsEmptyStr(usbuf.fullname)) {
cdb_delete(CDB_USERS, "", 0);
}
}
- /* Make sure user SYS_* is user 0 */
- while (CtdlGetUserByNumber(&usbuf, -1) == 0)
- {
- if (strncmp(usbuf.fullname, "SYS_", 4))
- { /* Delete any user 0 that doesn't start with SYS_ */
- makeuserkey(usernamekey, usbuf.fullname, cutusername(usbuf.fullname));
- cdb_delete(CDB_USERS, usernamekey, strlen(usernamekey));
- }
- else {
- usbuf.usernum = 0;
- CtdlPutUser(&usbuf);
- }
+ /* Delete any "user 0" accounts */
+ while (CtdlGetUserByNumber(&usbuf, -1) == 0) {
+ makeuserkey(usernamekey, usbuf.fullname);
+ cdb_delete(CDB_USERS, usernamekey, strlen(usernamekey));
}
}
}
+
+
+/*
+ * We found the legacy sieve config in the user's config room. Store the message number in the user record.
+ */
+void mifm_found_config(long msgnum, void *userdata) {
+ struct ctdluser *us = (struct ctdluser *)userdata;
+
+ us->msgnum_inboxrules = msgnum;
+ syslog(LOG_DEBUG, "user: <%s> inbox filter msgnum: <%ld>", us->fullname, us->msgnum_inboxrules);
+}
+
+
+/*
+ * Helper function for migrate_inbox_filter_msgnums()
+ */
+void mifm_backend(char *username, void *data) {
+ struct ctdluser us;
+ char roomname[ROOMNAMELEN];
+
+ if (CtdlGetUserLock(&us, username) == 0) {
+ /* Take a spin through the user's personal config room */
+ syslog(LOG_DEBUG, "Processing <%s> (%ld)", us.fullname, us.usernum);
+ snprintf(roomname, sizeof roomname, "%010ld.%s", us.usernum, USERCONFIGROOM);
+ if (CtdlGetRoom(&CC->room, roomname) == 0) {
+ CtdlForEachMessage(MSGS_LAST, 1, NULL, SIEVECONFIG, NULL, mifm_found_config, (void *)&us );
+ }
+ CtdlPutUserLock(&us);
+ }
+}
+
+
+/*
+ * Prior to version 930 we used a MIME type search to locate the user's inbox filter rules.
+ * This function locates those ruleset messages and simply stores the message number in the user record.
+ */
+void migrate_inbox_filter_msgnums(void)
+{
+ ForEachUser(mifm_backend, NULL);
+}
+
+
+/*
+ * Create a default administrator account so we can log in to a new installation
+ */
+void create_default_admin_account(void) {
+ struct ctdluser usbuf;
+
+ create_user(DEFAULT_ADMIN_USERNAME, CREATE_USER_DO_NOT_BECOME_USER, (-1));
+ CtdlGetUser(&usbuf, DEFAULT_ADMIN_USERNAME);
+ safestrncpy(usbuf.password, DEFAULT_ADMIN_PASSWORD, sizeof(usbuf.password));
+ usbuf.axlevel = AxAideU;
+ CtdlPutUser(&usbuf);
+ CtdlSetConfigStr("c_sysadm", DEFAULT_ADMIN_USERNAME);
+}
+
+
/*
* Based on the server version number reported by the existing database,
* run in-place data format upgrades until everything is up to date.
CtdlSetConfigInt("c_ep_mode", EXPIRE_MANUAL);
CtdlSetConfigInt("c_ep_value", 0);
}
+
+ /*
+ * If this is the first run on an empty database, create a default administrator
+ */
+ if (oldver == 0) {
+ create_default_admin_account();
+ }
}
if ((oldver > 000) && (oldver < 922)) {
ProcessOldStyleAdjRefCountQueue();
}
+
+ if ((oldver > 000) && (oldver < 930)) {
+ migrate_inbox_filter_msgnums();
+ }
+
}
return "upgrade";
}
+
CTDL_MODULE_INIT(upgrade)
{
- if(!threading)
- {
- move_inet_addrs_from_vcards_to_user_records();
+ if (!threading) {
post_startup_upgrades();
}
-
+
/* return our module name for the log */
return "upgrade";
}