Add two more memory-debug smbcontrol messages: these ones should
[ira/wip.git] / source3 / smbd / server.c
index 4599cef41fb09c9490cdb401a0a766dd523b739b..2f831cdd97a8e856b71097b91b6fa43b8a9e92be 100644 (file)
@@ -21,8 +21,6 @@
 
 #include "includes.h"
 
-pstring servicesf = CONFIGFILE;
-extern pstring debugf;
 extern fstring global_myworkgroup;
 extern pstring global_myname;
 
@@ -82,7 +80,8 @@ static void  killkids(void)
   process a sam sync message - not sure whether to do this here or
   somewhere else
 ****************************************************************************/
-static void msg_sam_sync(int msg_type, pid_t pid, void *buf, size_t len)
+static void msg_sam_sync(int UNUSED(msg_type), pid_t UNUSED(pid),
+                        void *UNUSED(buf), size_t UNUSED(len))
 {
         DEBUG(10, ("** sam sync message received, ignoring\n"));
 }
@@ -247,7 +246,7 @@ max can be %d\n",
 
                        /* check for sighup processing */
                        if (reload_after_sighup) {
-                               unbecome_user();
+                               change_to_root_user();
                                DEBUG(1,("Reloading services after SIGHUP\n"));
                                reload_services(False);
                                reload_after_sighup = False;
@@ -357,8 +356,8 @@ BOOL reload_services(BOOL test)
        if (lp_loaded()) {
                pstring fname;
                pstrcpy(fname,lp_configfile());
-               if (file_exist(fname,NULL) && !strcsequal(fname,servicesf)) {
-                       pstrcpy(servicesf,fname);
+               if (file_exist(fname,NULL) && !strcsequal(fname,dyn_CONFIGFILE)) {
+                       pstrcpy(dyn_CONFIGFILE,fname);
                        test = False;
                }
        }
@@ -370,7 +369,7 @@ BOOL reload_services(BOOL test)
 
        lp_killunused(conn_snum_used);
        
-       ret = lp_load(servicesf,False,False,True);
+       ret = lp_load(dyn_CONFIGFILE,False,False,True);
 
        load_printers();
 
@@ -393,7 +392,7 @@ BOOL reload_services(BOOL test)
        reset_stat_cache();
 
        /* this forces service parameters to be flushed */
-       become_service(NULL,True);
+       set_current_service(NULL,True);
 
        return(ret);
 }
@@ -426,7 +425,7 @@ static BOOL dump_core(void)
 {
        char *p;
        pstring dname;
-       pstrcpy(dname,debugf);
+       pstrcpy(dname,lp_logfile());
        if ((p=strrchr_m(dname,'/'))) *p=0;
        pstrcat(dname,"/corefiles");
        mkdir(dname,0700);
@@ -462,11 +461,11 @@ update the current smbd process count
 
 static void decrement_smbd_process_count(void)
 {
-       int total_smbds;
+       int32 total_smbds;
 
        if (lp_max_smbd_processes()) {
                total_smbds = 0;
-               tdb_change_int_atomic(conn_tdb_ctx(), "INFO/total_smbds", &total_smbds, -1);
+               tdb_change_int32_atomic(conn_tdb_ctx(), "INFO/total_smbds", &total_smbds, -1);
        }
 }
 
@@ -477,14 +476,19 @@ void exit_server(char *reason)
 {
        static int firsttime=1;
        extern char *last_inbuf;
+       extern struct auth_context *negprot_global_auth_context;
 
-
-       if (!firsttime) exit(0);
+       if (!firsttime)
+               exit(0);
        firsttime = 0;
 
-       unbecome_user();
+       change_to_root_user();
        DEBUG(2,("Closing connections\n"));
 
+       if (negprot_global_auth_context) {
+               (negprot_global_auth_context->free)(&negprot_global_auth_context);
+       }
+
        conn_close_all();
 
        invalidate_all_vuids();
@@ -558,10 +562,11 @@ usage on the program
 static void usage(char *pname)
 {
 
-       d_printf("Usage: %s [-DaoPh?Vb] [-d debuglevel] [-l log basename] [-p port]\n", pname);
+       d_printf("Usage: %s [-DaioPh?Vb] [-d debuglevel] [-l log basename] [-p port]\n", pname);
        d_printf("       [-O socket options] [-s services file]\n");
-       d_printf("\t-D                    Become a daemon\n");
+       d_printf("\t-D                    Become a daemon (default)\n");
        d_printf("\t-a                    Append to log file (default)\n");
+       d_printf("\t-i                    Run interactive (not a daemon)\n" );
        d_printf("\t-o                    Overwrite log file, don't append\n");
        d_printf("\t-h                    Print usage\n");
        d_printf("\t-?                    Print usage\n");
@@ -581,13 +586,15 @@ static void usage(char *pname)
  int main(int argc,char *argv[])
 {
        extern BOOL append_log;
+       extern char *optarg;
        /* shall I run as a daemon */
        BOOL is_daemon = False;
+       BOOL interactive = False;
        BOOL specified_logfile = False;
        int port = SMB_PORT;
        int opt;
-       extern char *optarg;
-       
+       pstring logfile;
+
 #ifdef HAVE_SET_AUTH_PARAMETERS
        set_auth_parameters(argc,argv);
 #endif
@@ -598,25 +605,30 @@ static void usage(char *pname)
                argc--;
        }
 
-       while ( EOF != (opt = getopt(argc, argv, "O:l:s:d:Dp:h?bVaof:")) )
+       while ( EOF != (opt = getopt(argc, argv, "O:l:s:d:Dp:h?bVaiof:")) )
                switch (opt)  {
                case 'O':
                        pstrcpy(user_socket_options,optarg);
                        break;
 
                case 's':
-                       pstrcpy(servicesf,optarg);
+                       pstrcpy(dyn_CONFIGFILE,optarg);
                        break;
 
                case 'l':
                        specified_logfile = True;
-                       slprintf(debugf, sizeof(debugf)-1, "%s/log.smbd", optarg);
+                       slprintf(logfile, sizeof(logfile)-1, "%s/log.smbd", optarg);
+                       lp_set_logfile(logfile);
                        break;
 
                case 'a':
                        append_log = True;
                        break;
 
+               case 'i':
+                       interactive = True;
+                       break;
+
                case 'o':
                        append_log = False;
                        break;
@@ -667,15 +679,15 @@ static void usage(char *pname)
 
        append_log = True;
 
-       TimeInit();
-
        if(!specified_logfile) {
-               slprintf(debugf, sizeof(debugf)-1, "%s/log.smbd", LOGFILEBASE);
+               slprintf(logfile, sizeof(logfile)-1, "%s/log.smbd",
+                        dyn_LOGFILEBASE);
+               lp_set_logfile(logfile);
        }
 
        pstrcpy(remote_machine, "smbd");
 
-       setup_logging(argv[0],False);
+       setup_logging(argv[0],interactive);
 
        /* we want to re-seed early to prevent time delays causing
            client problems at a later date. (tridge) */
@@ -717,7 +729,7 @@ static void usage(char *pname)
        reopen_logs();
 
        DEBUG(1,( "smbd version %s started.\n", VERSION));
-       DEBUGADD(1,( "Copyright Andrew Tridgell 1992-1998\n"));
+       DEBUGADD(1,( "Copyright Andrew Tridgell 1992-2002\n"));
 
        DEBUG(2,("uid=%d gid=%d euid=%d egid=%d\n",
                 (int)getuid(),(int)getgid(),(int)geteuid(),(int)getegid()));
@@ -771,11 +783,20 @@ static void usage(char *pname)
                is_daemon = True;
        }
 
-       if (is_daemon) {
+       if (is_daemon && !interactive) {
                DEBUG( 3, ( "Becoming a daemon.\n" ) );
                become_daemon();
        }
 
+#if HAVE_SETPGID
+       /*
+        * If we're interactive we want to set our own process group for
+        * signal management.
+        */
+       if (interactive)
+               setpgid( (pid_t)0, (pid_t)0);
+#endif
+
        if (!directory_exist(lp_lockdir(), NULL)) {
                mkdir(lp_lockdir(), 0755);
        }
@@ -787,11 +808,18 @@ static void usage(char *pname)
        if (!message_init()) {
                exit(1);
        }
+       register_msg_pool_usage();
+       register_dmalloc_msgs();
 
        /* Setup the main smbd so that we can get messages. */
        claim_connection(NULL,"",MAXSTATUS,True);
 
-       start_background_queue();
+       /* 
+          DO NOT ENABLE THIS TILL YOU COPE WITH KILLING THESE TASKS AND INETD
+          THIS *killed* LOTS OF BUILD FARM MACHINES. IT CREATED HUNDREDS OF 
+          smbd PROCESSES THAT NEVER DIE
+          start_background_queue(); 
+       */
 
        if (!open_sockets(is_daemon,port))
                exit(1);
@@ -819,13 +847,18 @@ static void usage(char *pname)
        /* possibly reload the services file. */
        reload_services(True);
 
-       if (init_group_mapping()==False) {
-               printf("Could not open tdb mapping file.\n");
+       if(!pdb_generate_sam_sid()) {
+               DEBUG(0,("ERROR: Samba cannot create a SAM SID.\n"));
+               exit(1);
+       }
+
+       if (!init_group_mapping()) {
+               DEBUG(0,("Could not open tdb mapping file.\n"));
                return 0;
        }
 
-       if(!pdb_generate_sam_sid()) {
-               DEBUG(0,("ERROR: Samba cannot create a SAM SID.\n"));
+       if (!init_account_policy()) {
+               DEBUG(0,("Could not open account policy tdb.\n"));
                exit(1);
        }
 
@@ -838,6 +871,11 @@ static void usage(char *pname)
        if (!init_oplocks()) {
                exit(1);
        }
+       
+       /* Setup mangle */
+       if (!init_mangle_tdb()) {
+               exit(1);
+       }
 
        /* Setup change notify */
        if (!init_change_notify()) {