On the first run of the server on an empty database, create a default administrator...
authorArt Cancro <ajc@citadel.org>
Mon, 21 Oct 2019 18:38:13 +0000 (14:38 -0400)
committerArt Cancro <ajc@citadel.org>
Mon, 21 Oct 2019 18:38:13 +0000 (14:38 -0400)
citadel/citadel.h
citadel/modules/upgrade/serv_upgrade.c

index 96908accef59c37d76e56d04f73dfa27ae294cd4..86777bf6542dc722e4304722e32edb01e22cb835 100644 (file)
@@ -47,6 +47,13 @@ extern "C" {
 #endif
 #endif
 
+/*
+ * This is the user name and password for the default administrator account
+ * that is created when Citadel Server is started with an empty database.
+ */
+#define DEFAULT_ADMIN_USERNAME "admin"
+#define DEFAULT_ADMIN_PASSWORD "citadel"
+
 /* Various length constants */
 
 #define ROOMNAMELEN    128             /* The size of a roomname string */
index 846a693e5ca2b2ebbc19022b2cc721535c96037c..1d29cfcd10d9ceea211857b6afa586a1b28bf0c7 100644 (file)
@@ -471,6 +471,21 @@ void move_inet_addrs_from_vcards_to_user_records(void)
 }
 
 
+/*
+ * 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.
@@ -536,6 +551,13 @@ void pre_startup_upgrades(void) {
                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();
+       }
 }