Merge from HEAD:
[tprouty/samba.git] / source / nsswitch / winbindd.c
index 4bfec1afe49338387de64b90fcc42b561631b027..b70a4dd3b4039fda8b8989930f803cb626b1288e 100644 (file)
@@ -58,6 +58,25 @@ static BOOL reload_services_file(BOOL test)
        return(ret);
 }
 
+/*******************************************************************
+ Print out all talloc memory info.
+********************************************************************/
+
+void return_all_talloc_info(int msg_type, pid_t src_pid, void *buf, size_t len)
+{
+       TALLOC_CTX *ctx = talloc_init("info context");
+       char *info = NULL;
+
+       if (!ctx)
+               return;
+
+       info = talloc_describe_all(ctx);
+       if (info)
+               DEBUG(10,(info));
+       message_send_pid(src_pid, MSG_TALLOC_USAGE, info, info ? strlen(info) + 1: 0, True);
+       talloc_destroy(ctx);
+}
+
 #if DUMP_CORE
 
 /**************************************************************************** **
@@ -188,7 +207,7 @@ static void sighup_handler(int signum)
 struct dispatch_table {
        enum winbindd_cmd cmd;
        enum winbindd_result (*fn)(struct winbindd_cli_state *state);
-       char *winbindd_cmd_name;
+       const char *winbindd_cmd_name;
 };
 
 static struct dispatch_table dispatch_table[] = {
@@ -245,6 +264,7 @@ static struct dispatch_table dispatch_table[] = {
        { WINBINDD_INFO, winbindd_info, "INFO" },
        { WINBINDD_INTERFACE_VERSION, winbindd_interface_version, "INTERFACE_VERSION" },
        { WINBINDD_DOMAIN_NAME, winbindd_domain_name, "DOMAIN_NAME" },
+       { WINBINDD_NETBIOS_NAME, winbindd_netbios_name, "NETBIOS_NAME" },
 
        /* WINS functions */
 
@@ -362,7 +382,7 @@ void winbind_process_packet(struct winbindd_cli_state *state)
        /* Process request */
        
        /* Ensure null termination of entire request */
-       state->request.domain[sizeof(state->request.domain)-1]='\0';
+       state->request.null_term = '\0';
 
        state->pid = state->request.pid;
        
@@ -519,6 +539,12 @@ static void process_loop(void)
                /* Initialise fd lists for select() */
 
                listen_sock = open_winbindd_socket();
+
+               if (listen_sock == -1) {
+                       perror("open_winbind_socket");
+                       exit(1);
+               }
+
                maxfd = listen_sock;
 
                FD_ZERO(&r_fds);
@@ -689,12 +715,6 @@ BOOL winbind_setup_common(void)
        if (!winbindd_param_init())
                return False;
 
-       /* Get list of domains we look up requests for.  This includes the
-          domain which we are a member of as well as any trusted
-          domains. */ 
-
-       init_domain_list();
-
        /* Winbind daemon initialisation */
 
        if (!winbindd_idmap_init())
@@ -733,6 +753,8 @@ struct winbindd_state server_state;   /* Server state information */
 static void usage(void)
 {
        printf("Usage: winbindd [options]\n");
+        printf("\t-F                daemon in foreground mode\n");
+        printf("\t-S                log to stdout\n");
        printf("\t-i                interactive mode\n");
        printf("\t-B                dual daemon mode\n");
        printf("\t-n                disable cacheing\n");
@@ -746,6 +768,8 @@ static void usage(void)
        extern BOOL AllowDebugChange;
        pstring logfile;
        BOOL interactive = False;
+       BOOL Fork = True;
+       BOOL log_stdout = False;
        int opt;
 
        /* glibc (?) likes to print "User defined signal 1" and exit if a
@@ -770,12 +794,20 @@ static void usage(void)
 
        /* Initialise samba/rpc client stuff */
 
-       while ((opt = getopt(argc, argv, "id:s:nhB")) != EOF) {
+       while ((opt = getopt(argc, argv, "FSid:s:nhB")) != EOF) {
                switch (opt) {
 
+               case 'F':
+                       Fork = False;
+                       break;
+               case 'S':
+                       log_stdout = True;
+                       break;
                        /* Don't become a daemon */
                case 'i':
                        interactive = True;
+                       log_stdout = True;
+                       Fork = False;
                        break;
 
                        /* dual daemon system */
@@ -809,9 +841,15 @@ static void usage(void)
                }
        }
 
+       if (log_stdout && Fork) {
+               printf("Can't log to stdout (-S) unless daemon is in foreground +(-F) or interactive (-i)\n");
+               usage();
+               exit(1);
+       }
+
        snprintf(logfile, sizeof(logfile), "%s/log.winbindd", dyn_LOGFILEBASE);
        lp_set_logfile(logfile);
-       setup_logging("winbindd", interactive);
+       setup_logging("winbindd", log_stdout);
        reopen_logs();
 
        DEBUG(1, ("winbindd version %s started.\n", VERSION ) );
@@ -828,7 +866,7 @@ static void usage(void)
                exit(1);
 
        if (!interactive) {
-               become_daemon();
+               become_daemon(Fork);
                pidfile_create("winbindd");
        }
 
@@ -858,6 +896,7 @@ static void usage(void)
        }
 
        register_msg_pool_usage();
+       message_register(MSG_REQ_TALLOC_USAGE, return_all_talloc_info);
 
        /* Loop waiting for requests */