// guesses about what kind of data format changes need to be applied, and
// we apply them transparently.
//
-// Copyright (c) 1987-2022 by the citadel.org team
+// Copyright (c) 1987-2023 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 <string.h>
#include <limits.h>
#include <libcitadel.h>
-#include "../../citadel.h"
+#include "../../citadel_defs.h"
#include "../../server.h"
#include "../../citserver.h"
#include "../../support.h"
#include "../../control.h"
#include "../../database.h"
#include "../../user_ops.h"
+#include "../../makeuserkey.h"
#include "../../msgbase.h"
#include "serv_upgrade.h"
#include "../../euidindex.h"
// We keep this value around for the entire duration of the program run because we'll need it during several stages of startup.
int oldver = 0;
-// Try to remove any extra users with number 0
-void fix_sys_user_name(void) {
- struct ctdluser usbuf;
- char usernamekey[USERNAME_SIZE];
-
- while (CtdlGetUserByNumber(&usbuf, 0) == 0) {
- // delete user with number 0 and no name
- if (IsEmptyStr(usbuf.fullname)) {
- cdb_delete(CDB_USERS, "", 0);
- }
- else {
- // temporarily set this user to -1
- usbuf.usernum = -1;
- CtdlPutUser(&usbuf);
- }
- }
-
- // Delete any "user 0" accounts
- while (CtdlGetUserByNumber(&usbuf, -1) == 0) {
- makeuserkey(usernamekey, usbuf.fullname);
- cdb_delete(CDB_USERS, usernamekey, strlen(usernamekey));
- }
-}
-
-
-// Back end processing function for reindex_uids()
-void reindex_uids_backend(char *username, void *data) {
-
- struct ctdluser us;
-
- if (CtdlGetUserLock(&us, username) == 0) {
- syslog(LOG_DEBUG, "Processing <%s> (%d)", us.fullname, us.uid);
- if (us.uid == CTDLUID) {
- us.uid = NATIVE_AUTH_UID;
- }
- CtdlPutUserLock(&us);
- if ((us.uid > 0) && (us.uid != NATIVE_AUTH_UID)) { // if non-native auth , index by uid
- StrBuf *claimed_id = NewStrBuf();
- StrBufPrintf(claimed_id, "uid:%d", us.uid);
- attach_extauth(&us, claimed_id);
- FreeStrBuf(&claimed_id);
- }
- }
-}
-
-
-// Build extauth index of all users with uid-based join (system auth, LDAP auth)
-// Also changes all users with a uid of CTDLUID to NATIVE_AUTH_UID (-1)
-void reindex_uids(void) {
- syslog(LOG_WARNING, "upgrade: reindexing and applying uid changes");
- ForEachUser(reindex_uids_backend, NULL);
- return;
-}
-
-
-// These accounts may have been created by code that ran between mid 2008 and early 2011.
-// If present they are no longer in use and may be deleted.
-void remove_thread_users(void) {
- char *deleteusers[] = {
- "SYS_checkpoint",
- "SYS_extnotify",
- "SYS_IGnet Queue",
- "SYS_indexer",
- "SYS_network",
- "SYS_popclient",
- "SYS_purger",
- "SYS_rssclient",
- "SYS_select_on_master",
- "SYS_SMTP Send"
- };
-
- int i;
- struct ctdluser usbuf;
- for (i=0; i<(sizeof(deleteusers)/sizeof(char *)); ++i) {
- if (CtdlGetUser(&usbuf, deleteusers[i]) == 0) {
- usbuf.axlevel = 0;
- strcpy(usbuf.password, "deleteme");
- CtdlPutUser(&usbuf);
- syslog(LOG_INFO,
- "System user account <%s> is no longer in use and will be deleted.",
- deleteusers[i]
- );
- }
- }
-}
-
// Attempt to guess the name of the time zone currently in use
// on the underlying host system.
encoded_data = malloc((data_length * 2) + 100);
if (encoded_data) {
sprintf(encoded_data, "Content-type: text/plain\nContent-transfer-encoding: base64\n\n");
- CtdlEncodeBase64(&encoded_data[strlen(encoded_data)], unencoded_data, data_length, 1);
+ CtdlEncodeBase64(&encoded_data[strlen(encoded_data)], unencoded_data, data_length, BASE64_YES_LINEBREAKS);
snprintf(subject, sizeof subject, "Imported room banner for %s", roomname);
info_msgnum = quickie_message("Citadel", NULL, NULL, SYSCONFIGROOM, encoded_data, FMT_RFC822, subject);
free(encoded_data);
encoded_data = malloc((data_length * 2) + 100);
if (encoded_data) {
sprintf(encoded_data, "Content-type: image/gif\nContent-transfer-encoding: base64\n\n");
- CtdlEncodeBase64(&encoded_data[strlen(encoded_data)], unencoded_data, data_length, 1);
+ CtdlEncodeBase64(&encoded_data[strlen(encoded_data)], unencoded_data, data_length, BASE64_YES_LINEBREAKS);
snprintf(subject, sizeof subject, "Imported room icon for %s", roomname);
pic_msgnum = quickie_message("Citadel", NULL, NULL, SYSCONFIGROOM, encoded_data, FMT_RFC822, subject);
free(encoded_data);
// For new installations (oldver == 0) also set default values.
void update_config(void) {
- if (oldver < 606) {
+ if (oldver < 811) {
CtdlSetConfigInt("c_rfc822_strict_from", 0);
- }
-
- if (oldver < 609) {
CtdlSetConfigInt("c_purge_hour", 3);
- }
-
- if (oldver < 615) {
CtdlSetConfigInt("c_ldap_port", 389);
- }
-
- if (oldver < 623) {
CtdlSetConfigStr("c_ip_addr", "*");
- }
-
- if (oldver < 650) {
CtdlSetConfigInt("c_enable_fulltext", 1);
- }
-
- if (oldver < 652) {
- CtdlSetConfigInt("c_auto_cull", 1);
- }
-
- if (oldver < 725) {
CtdlSetConfigInt("c_xmpp_c2s_port", 5222);
CtdlSetConfigInt("c_xmpp_s2s_port", 5269);
}
}
+void regenerate_secondary_indices(void) {
+ syslog(LOG_INFO, "regenerate_secondary_indices has been activated.");
+
+ rebuild_usersbynumber();
+ rebuild_euid_index();
+ CtdlRebuildDirectoryIndex();
+ // we also need to trigger the fulltext foo
+
+ CtdlSetConfigInt("regenerate_secondary_indices", 0);
+}
+
+
// Based on the server version number reported by the existing database,
// run in-place data format upgrades until everything is up to date.
void pre_startup_upgrades(void) {
return;
}
- if ((oldver > 000) && (oldver < 591)) {
+ // After 2026-may-06 we will do the following:
+ // 1. Set the oldest upgradable version to 902 (it will then be ten years old)
+ // 2. Remove support for upgrading from the legacy config and control file formats.
+
+ // Currently, the oldest upgradable version is 811, which was released on 2012-may-21
+
+ if ((oldver > 000) && (oldver < 811)) {
syslog(LOG_EMERG, "This database is too old to be upgraded. Citadel server will exit.");
exit(EXIT_FAILURE);
}
- if ((oldver > 000) && (oldver < 913)) {
- reindex_uids();
- }
- if ((oldver > 000) && (oldver < 659)) {
- rebuild_euid_index();
- }
- if (oldver < 735) {
- fix_sys_user_name();
- }
- if (oldver < 736) {
- rebuild_usersbynumber();
- }
- if (oldver < 790) {
- remove_thread_users();
- }
- if (oldver < 810) {
- struct ctdlroom QRoom;
- if (!CtdlGetRoom(&QRoom, SMTP_SPOOLOUT_ROOM)) {
- QRoom.QRdefaultview = VIEW_QUEUE;
- CtdlPutRoom(&QRoom);
- }
- }
-
if ((oldver > 000) && (oldver < 902)) {
ingest_old_roominfo_and_roompic_files();
}
+ if ((oldver > 000) && (oldver < 973)) { // This was the old extauth table.
+ cdb_trunc(CDB_UNUSED1); // We will do this better someday.
+ }
+ if ((oldver > 000) && (oldver < 975)) { // An unrepairable defect was found in this table.
+ cdb_trunc(CDB_USETABLE); // We have to discard it and start over.
+ }
CtdlSetConfigInt("MM_hosted_upgrade_level", REV_LEVEL);
if (oldver < REV_LEVEL) {
syslog(LOG_WARNING, "Running post-startup database upgrades.");
- }
- else {
- return;
- }
-
- if ((oldver > 000) && (oldver < 912)) {
- move_inet_addrs_from_vcards_to_user_records();
- }
-
- if ((oldver > 000) && (oldver < 922)) {
- ProcessOldStyleAdjRefCountQueue();
- }
- if ((oldver > 000) && (oldver < 930)) {
- migrate_inbox_filter_msgnums();
+ if ((oldver > 000) && (oldver < 912)) {
+ move_inet_addrs_from_vcards_to_user_records();
+ }
+
+ if ((oldver > 000) && (oldver < 922)) {
+ ProcessOldStyleAdjRefCountQueue();
+ }
+
+ if ((oldver > 000) && (oldver < 930)) {
+ migrate_inbox_filter_msgnums();
+ }
}
-
}
+// Initialization function, called from modules_init.c
char *ctdl_module_init_upgrade(void) {
if (!threading) {
post_startup_upgrades();