- static int already_have_control = 0;
- int rv = 0;
-
- /*
- * If we already have the control record in memory, there's no point
- * in reading it from disk again.
- */
- if (already_have_control) return;
-
- /* Zero it out. If the control record on disk is missing or short,
- * the system functions with all control record fields initialized
- * to zero.
- */
- memset(&CitControl, 0, sizeof(struct CitControl));
- if (control_fp == NULL) {
- control_fp = fopen(file_citadel_control, "rb+");
- if (control_fp != NULL) {
- lock_control();
- rv = fchown(fileno(control_fp), config.c_ctdluid, -1);
- if (rv == -1)
- syslog(LOG_EMERG, "Failed to adjust ownership of: %s [%s]\n",
- file_citadel_control, strerror(errno));
- rv = fchmod(fileno(control_fp), S_IRUSR|S_IWUSR);
- if (rv == -1)
- syslog(LOG_EMERG, "Failed to adjust accessrights of: %s [%s]\n",
- file_citadel_control, strerror(errno));
- }
- }
- if (control_fp == NULL) {
- control_fp = fopen(file_citadel_control, "wb+");
- if (control_fp != NULL) {
- lock_control();
- memset(&CitControl, 0, sizeof(struct CitControl));
-
- rv = fchown(fileno(control_fp), config.c_ctdluid, -1);
- if (rv == -1)
- syslog(LOG_EMERG, "Failed to adjust ownership of: %s [%s]\n",
- file_citadel_control, strerror(errno));
-
- rv = fchmod(fileno(control_fp), S_IRUSR|S_IWUSR);
- if (rv == -1)
- syslog(LOG_EMERG, "Failed to adjust accessrights of: %s [%s]\n",
- file_citadel_control, strerror(errno));
- rv = fwrite(&CitControl, sizeof(struct CitControl), 1, control_fp);
- if (rv == -1)
- syslog(LOG_EMERG, "Failed to write: %s [%s]\n",
- file_citadel_control, strerror(errno));
- rewind(control_fp);
+ FILE *fp = NULL;
+ struct legacy_ctrl_format c;
+ memset(&c, 0, sizeof(c));
+
+ fp = fopen(file_citadel_control, "rb+");
+ if (fp != NULL) {
+ syslog(LOG_INFO, "Legacy format control record found -- importing to db");
+ fread(&c, sizeof(struct legacy_ctrl_format), 1, fp);
+
+ CtdlSetConfigLong( "MMhighest", c.MMhighest);
+ CtdlSetConfigInt( "MMflags", c.MMflags);
+ CtdlSetConfigLong( "MMnextuser", c.MMnextuser);
+ CtdlSetConfigLong( "MMnextroom", c.MMnextroom);
+ CtdlSetConfigInt( "MM_hosted_upgrade_level", c.MM_hosted_upgrade_level);
+ CtdlSetConfigInt( "MM_fulltext_wordbreaker", c.MM_fulltext_wordbreaker);
+ CtdlSetConfigLong( "MMfulltext", c.MMfulltext);
+
+ fclose(fp);
+ if (unlink(file_citadel_control) != 0) {
+ fprintf(stderr, "Unable to remove legacy control record %s after migrating it.\n", file_citadel_control);
+ fprintf(stderr, "Exiting to prevent data corruption.\n");
+ exit(CTDLEXIT_CONFIG);