reload_services needs to be called prior to init_files but after
[samba.git] / source3 / smbd / server.c
index 68f722ff51b0795dc37629dad5fe3b8f302b362f..9b397bcdeb7dc0e429551d4c8c843272529e9971 100644 (file)
@@ -25,6 +25,7 @@
 pstring servicesf = CONFIGFILE;
 extern pstring debugf;
 extern fstring global_myworkgroup;
+extern fstring global_sam_name;
 extern pstring global_myname;
 
 int am_parent = 1;
@@ -428,6 +429,13 @@ void exit_server(char *reason)
        locking_end();
 
        DEBUG(3,("Server exit (%s)\n", (reason ? reason : "")));
+#ifdef MEM_MAN
+       {
+               extern FILE *dbf;
+               smb_mem_write_verbose(dbf);
+               dbgflush();
+       }
+#endif
        exit(0);
 }
 
@@ -436,35 +444,12 @@ void exit_server(char *reason)
 /****************************************************************************
   initialise connect, service and file structs
 ****************************************************************************/
-static void init_structs(void )
+static void init_structs(void)
 {
-       get_myname(myhostname,NULL);
-
-       /*
-        * Set the machine NETBIOS name if not already
-        * set from the config file.
-        */
-
-       if (!*global_myname) {
-               char *p;
-               fstrcpy( global_myname, myhostname );
-               p = strchr( global_myname, '.' );
-               if (p) 
-                       *p = 0;
-       }
-
-       strupper( global_myname );
-
        conn_init();
-
        file_init();
-
-       /* for RPC pipes */
-       init_rpc_pipe_hnd();
-
-       /* for LSA handles */
-       init_lsa_policy_hnd();
-
+       init_rpc_pipe_hnd(); /* for RPC pipes */
+       init_lsa_policy_hnd(); /* for LSA handles */
        init_dptrs();
 }
 
@@ -545,7 +530,7 @@ static void usage(char *pname)
           so set our umask to 0 */
        umask(0);
 
-       GetWd(OriginalDir);
+       dos_GetWd(OriginalDir);
 
        init_uid();
 
@@ -627,11 +612,23 @@ static void usage(char *pname)
                exit(1);
        }
 
+       get_myname(myhostname,NULL);
+
        if (!reload_services(False))
                return(-1);     
 
        init_structs();
        
+       /*
+        * Set the machine NETBIOS name if not already
+        * set from the config file.
+        */
+       if (!*global_myname)
+       {
+               fstrcpy(global_myname, dns_to_netbios_name(myhostname));
+       }
+       strupper(global_myname);
+
 #ifdef WITH_SSL
        {
                extern BOOL sslEnabled;
@@ -643,10 +640,40 @@ static void usage(char *pname)
 
        codepage_initialise(lp_client_code_page());
 
-       fstrcpy(global_myworkgroup, lp_workgroup());
+       if (!pwdb_initialise(True))
+       {
+               exit(1);
+       }
+
+       if(!initialise_sam_password_db())
+       {
+               exit(1);
+       }
+
+       if(!initialise_passgrp_db())
+       {
+               exit(1);
+       }
+
+       if(!initialise_group_db())
+       {
+               exit(1);
+       }
 
-       if(!pdb_generate_sam_sid()) {
-               DEBUG(0,("ERROR: Samba cannot create a SAM SID.\n"));
+       if(!initialise_alias_db())
+       {
+               exit(1);
+       }
+
+       if(!initialise_builtin_db())
+       {
+               exit(1);
+       }
+
+       if (!get_member_domain_sid())
+       {
+               DEBUG(0,("ERROR: Samba cannot obtain PDC SID from PDC(s) %s.\n",
+                         lp_passwordserver()));
                exit(1);
        }
 
@@ -680,7 +707,7 @@ static void usage(char *pname)
                become_daemon();
        }
 
-    check_kernel_oplocks();
+       check_kernel_oplocks();
 
        if (!directory_exist(lp_lockdir(), NULL)) {
                mkdir(lp_lockdir(), 0755);
@@ -696,9 +723,6 @@ static void usage(char *pname)
        if (!locking_init(0))
                exit(1);
 
-       if(!initialize_password_db())
-               exit(1);
-
        /* possibly reload the services file. */
        reload_services(True);