From 77dda21d935c40c383141b39ba4f29941ef6f284 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Tue, 13 Jun 2023 20:18:24 -0900 Subject: [PATCH] rescue mode --- citadel/server/server_main.c | 18 +++++++++++++++--- citadel/server/user_ops.c | 13 +++++++++++++ citadel/server/user_ops.h | 2 ++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/citadel/server/server_main.c b/citadel/server/server_main.c index ff526ff05..294df3a5c 100644 --- a/citadel/server/server_main.c +++ b/citadel/server/server_main.c @@ -25,6 +25,7 @@ uid_t ctdluid = 0; const char *CitadelServiceUDS="citadel-UDS"; const char *CitadelServiceTCP="citadel-TCP"; int sanity_diag_mode = 0; +char *rescue_string = NULL; // Create or remove a lock file, so we only have one Citadel Server running at a time. @@ -85,7 +86,7 @@ int main(int argc, char **argv) { // parse command-line arguments int g; - while ((g=getopt(argc, argv, "cl:dh:x:t:B:Dru:s:")) != EOF) switch(g) { + while ((g=getopt(argc, argv, "cl:dh:x:t:B:Dru:s:R:")) != EOF) switch(g) { // test this binary for compatibility and exit case 'c': @@ -148,6 +149,11 @@ int main(int argc, char **argv) { sanity_diag_mode = atoi(optarg); break; + // -R is an undocumented rescue mode that you should never use + case 'R': + rescue_string = strdup(optarg); + break; + // any other parameter makes it crash and burn default: fprintf(stderr, "citserver: usage: " @@ -293,8 +299,14 @@ int main(int argc, char **argv) { // We want to check for idle sessions once per minute CtdlRegisterSessionHook(terminate_idle_sessions, EVT_TIMER, PRIO_CLEANUP + 1); - // Go into multithreaded mode. When this call exits, the server is stopping. - go_threading(); + // Are we in the undocumented rescue mode? + if (rescue_string) { + undocumented_rescue_mode(rescue_string); + } + else { + // Go into multithreaded mode. When this call exits, the server is stopping. + go_threading(); + } // Get ready to shut down the server. int exit_code = master_cleanup(exit_signal); diff --git a/citadel/server/user_ops.c b/citadel/server/user_ops.c index a801c0e8b..55cbf574a 100644 --- a/citadel/server/user_ops.c +++ b/citadel/server/user_ops.c @@ -1137,3 +1137,16 @@ int InitialMailCheck() { return(num_newmsgs); } + + +// Undocumented rescue mode +void undocumented_rescue_mode(char *rescue_string) { + struct ctdluser usbuf; + memset(&usbuf, 0, sizeof(struct ctdluser)); + extract_token(usbuf.fullname, rescue_string, 0, '|', sizeof usbuf.password); + extract_token(usbuf.password, rescue_string, 1, '|', sizeof usbuf.password); + usbuf.usernum = extract_long(rescue_string, 2); + usbuf.axlevel = 6; + usbuf.lastcall = time(NULL); + CtdlPutUser(&usbuf); +} diff --git a/citadel/server/user_ops.h b/citadel/server/user_ops.h index b7296ab88..28c242921 100644 --- a/citadel/server/user_ops.h +++ b/citadel/server/user_ops.h @@ -62,4 +62,6 @@ void makeuserkey(char *key, const char *username); int CtdlUserCmp(char *s1, char *s2); int internal_create_user(char *username, struct ctdluser *usbuf, uid_t uid); +void undocumented_rescue_mode(char *); + #endif -- 2.39.2