rescue mode
authorArt Cancro <ajc@citadel.org>
Wed, 14 Jun 2023 05:18:24 +0000 (20:18 -0900)
committerArt Cancro <ajc@citadel.org>
Wed, 14 Jun 2023 05:18:24 +0000 (20:18 -0900)
citadel/server/server_main.c
citadel/server/user_ops.c
citadel/server/user_ops.h

index ff526ff05e9b3b1d6226cfb00d37f8659fc4cffd..294df3a5ceb631031fdaff92bb47921cda88f156 100644 (file)
@@ -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);
index a801c0e8b494b16cfc3185b6a08ebd0776d68097..55cbf574a0e4df7ecbcda0a1abd176e3f3fe5032 100644 (file)
@@ -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);
+}
index b7296ab8816071ad6d123242f39b867939abb145..28c2429214ce8e7cd97d9b08e5c935b3fdd71b66 100644 (file)
@@ -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