From: Art Cancro Date: Mon, 21 Oct 2019 18:38:13 +0000 (-0400) Subject: On the first run of the server on an empty database, create a default administrator... X-Git-Tag: v939~263 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=79609016818c50dedddfbb778de3ba9678391ddc On the first run of the server on an empty database, create a default administrator account. This should eliminate the need to run setup on most systems. --- diff --git a/citadel/citadel.h b/citadel/citadel.h index 96908acce..86777bf65 100644 --- a/citadel/citadel.h +++ b/citadel/citadel.h @@ -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 */ diff --git a/citadel/modules/upgrade/serv_upgrade.c b/citadel/modules/upgrade/serv_upgrade.c index 846a693e5..1d29cfcd1 100644 --- a/citadel/modules/upgrade/serv_upgrade.c +++ b/citadel/modules/upgrade/serv_upgrade.c @@ -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(); + } }