reload_services needs to be called prior to init_files but after
[samba.git] / source3 / smbd / server.c
index c06c0ce1cb42dd7cb5d9138f0244a46b9288489d..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;
@@ -240,6 +241,14 @@ max can be %d\n",
                                   that client substitutions will be
                                   done correctly in the process.  */
                                reset_globals_after_fork();
+
+                /*
+                 * Ensure this child has kernel oplock
+                 * capabilities, but not it's children.
+                 */
+                set_process_capability(KERNEL_OPLOCK_CAPABILITY, True);
+                set_inherited_process_capability(KERNEL_OPLOCK_CAPABILITY, False);
+
                                return True; 
                        }
                        /* The parent doesn't need this socket */
@@ -420,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);
 }
 
@@ -428,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();
 }
 
@@ -478,6 +471,7 @@ static void usage(char *pname)
        printf("\t-P                    passive only\n");
        printf("\t-a                    append to log file (default)\n");
        printf("\t-o                    overwrite log file, don't append\n");
+       printf("\t-i scope              NetBIOS scope to use (default none)\n");
        printf("\n");
 }
 
@@ -536,7 +530,7 @@ static void usage(char *pname)
           so set our umask to 0 */
        umask(0);
 
-       GetWd(OriginalDir);
+       dos_GetWd(OriginalDir);
 
        init_uid();
 
@@ -618,11 +612,23 @@ static void usage(char *pname)
                exit(1);
        }
 
-       init_structs();
-       
+       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;
@@ -634,10 +640,40 @@ static void usage(char *pname)
 
        codepage_initialise(lp_client_code_page());
 
-       pstrcpy(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(!initialise_alias_db())
+       {
+               exit(1);
+       }
 
-       if(!pdb_generate_machine_sid()) {
-               DEBUG(0,("ERROR: Samba cannot get a machine SID.\n"));
+       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);
        }
 
@@ -671,6 +707,8 @@ static void usage(char *pname)
                become_daemon();
        }
 
+       check_kernel_oplocks();
+
        if (!directory_exist(lp_lockdir(), NULL)) {
                mkdir(lp_lockdir(), 0755);
        }
@@ -685,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);
        
@@ -700,8 +735,6 @@ static void usage(char *pname)
        if( !open_oplock_ipc() )
                exit(1);
 
-    check_kernel_oplocks();
-
        smbd_process();
        close_sockets();