A few more API clean ups. Mainly revolving around user_ops.c
[citadel.git] / citadel / server_main.c
index 37c77ddcd4fa8068ba0b16436d089f3d5d21900d..71f81feb398936e5499db698ebcc6451e099641d 100644 (file)
@@ -55,7 +55,7 @@
 #include "user_ops.h"
 #include "housekeeping.h"
 #include "svn_revision.h"
-#include "citadel_dirs.c"
+#include "citadel_dirs.h"
 
 #include "modules_init.h"
 #include "ecrash.h"
@@ -133,7 +133,6 @@ int main(int argc, char **argv)
                        else
                                safestrncpy(relhome, &argv[a][2],
                                                        sizeof relhome);
-                       home_specified = 1;
                        home=1;
                }
 
@@ -214,6 +213,11 @@ int main(int argc, char **argv)
        CtdlLogPrintf(CTDL_INFO, "Loading citadel.config\n");
        get_config();
        config.c_ipgm_secret = rand();
+
+       /* get_control() MUST MUST MUST be called BEFORE the databases are opened!! */
+       CtdlLogPrintf(CTDL_INFO, "Acquiring control record\n");
+       get_control();
+
        put_config();
 
 #ifdef HAVE_RUN_DIR
@@ -244,21 +248,26 @@ int main(int argc, char **argv)
         */
        master_startup();
 
-       CtdlLogPrintf(CTDL_INFO, "Acquiring control record\n");
-       get_control();
-
+       /*
+        * Check that the control record is correct and place sensible values if it isn't
+        */
+       check_control();
+       
+       /*
+        * Run any upgrade entry points
+        */
+       CtdlLogPrintf(CTDL_INFO, "Upgrading modules.\n");
+       upgrade_modules();
        
 /**
- * Initialise the user 0 to have a name. It would be nice to do it in InitializeMasterCC
- * since it is contained within the MasterCC but we can't because the DB isn't available
- * at that time so we do it seperate.
+ * Load the user for the masterCC or create them if they don't exist
  */
-       /** Give user 0 a name and create them if necessary */
-       if (getuser(&masterCC.user, "Citadel"))
+       if (CtdlGetUser(&masterCC.user, "SYS_Citadel"))
        {
-               getuserbynumber(&masterCC.user, 0);
-               strcpy (masterCC.user.fullname, "Citadel");
-               putuser(&masterCC.user);
+               /** User doesn't exist. We can't use create user here as the user number needs to be 0 */
+               strcpy (masterCC.user.fullname, "SYS_Citadel") ;
+               CtdlPutUser(&masterCC.user);
+               CtdlGetUser(&masterCC.user, "SYS_Citadel"); /** Just to be safe */
        }
        
        /*
@@ -282,11 +291,6 @@ int main(int argc, char **argv)
                                CitadelServiceTCP);
 
                                
-       /*
-        * Run any upgrade entry points
-        */
-       CtdlLogPrintf(CTDL_INFO, "Upgrading modules.\n");
-       upgrade_modules();
        
        
        /*
@@ -306,6 +310,14 @@ int main(int argc, char **argv)
                start_chkpwd_daemon();
        }
 
+
+       /*
+        * check, whether we're fired up another time after a crash.
+        * if, post an aide message, so the admin has a chance to react.
+        */
+       checkcrash ();
+
+
        /*
         * Now that we've bound the sockets, change to the Citadel user id and its
         * corresponding group ids