Fix bug #9104 - winbindd can mis-identify idle clients - can cause crashes and NDR...
[samba.git] / source3 / winbindd / winbindd.c
index 9c676f030300ab7342b3b40406e9ad4760b60a89..4442c73dbe8773aca00714b24c400a36e03bc0ba 100644 (file)
@@ -67,11 +67,12 @@ static bool reload_services_file(const char *lfile)
        bool ret;
 
        if (lp_loaded()) {
-               const char *fname = lp_configfile();
+               char *fname = lp_configfile();
 
                if (file_exist(fname) && !strcsequal(fname,get_dyn_CONFIGFILE())) {
                        set_dyn_CONFIGFILE(fname);
                }
+               TALLOC_FREE(fname);
        }
 
        /* if this is a child, restore the logfile to the special
@@ -565,6 +566,7 @@ static void process_request(struct winbindd_cli_state *state)
 
        state->cmd_name = "unknown request";
        state->recv_fn = NULL;
+       state->last_access = time(NULL);
 
        /* Process command */
 
@@ -870,7 +872,8 @@ static bool remove_idle_client(void)
        int nidle = 0;
 
        for (state = winbindd_client_list(); state; state = state->next) {
-               if (state->response == NULL &&
+               if (state->request == NULL &&
+                   state->response == NULL &&
                    !state->pwent_state && !state->grent_state) {
                        nidle++;
                        if (!last_access || state->last_access < last_access) {
@@ -903,17 +906,15 @@ static void winbindd_listen_fde_handler(struct tevent_context *ev,
        struct winbindd_listen_state *s = talloc_get_type_abort(private_data,
                                          struct winbindd_listen_state);
 
-       while (winbindd_num_clients() >
-              WINBINDD_MAX_SIMULTANEOUS_CLIENTS - 1) {
+       while (winbindd_num_clients() > lp_winbind_max_clients() - 1) {
                DEBUG(5,("winbindd: Exceeding %d client "
                         "connections, removing idle "
-                        "connection.\n",
-                        WINBINDD_MAX_SIMULTANEOUS_CLIENTS));
+                        "connection.\n", lp_winbind_max_clients()));
                if (!remove_idle_client()) {
                        DEBUG(0,("winbindd: Exceeding %d "
                                 "client connections, no idle "
                                 "connection found\n",
-                                WINBINDD_MAX_SIMULTANEOUS_CLIENTS));
+                                lp_winbind_max_clients()));
                        break;
                }
        }
@@ -1013,7 +1014,6 @@ int main(int argc, char **argv, char **envp)
        poptContext pc;
        int opt;
        TALLOC_CTX *frame = talloc_stackframe();
-       struct tevent_timer *te;
 
        /* glibc (?) likes to print "User defined signal 1" and exit if a
           SIGUSR[12] is received before a handler is installed */
@@ -1075,6 +1075,15 @@ int main(int argc, char **argv, char **envp)
                }
        }
 
+       /* We call dump_core_setup one more time because the command line can
+        * set the log file or the log-basename and this will influence where
+        * cores are stored. Without this call get_dyn_LOGFILEBASE will be
+        * the default value derived from build's prefix. For EOM this value
+        * is often not related to the path where winbindd is actually run
+        * in production.
+        */
+       dump_core_setup("winbindd");
+
        if (is_daemon && interactive) {
                d_fprintf(stderr,"\nERROR: "
                          "Option -i|--interactive is not allowed together with -D|--daemon\n\n");
@@ -1109,6 +1118,11 @@ int main(int argc, char **argv, char **envp)
                DEBUG(0, ("error opening config file\n"));
                exit(1);
        }
+       /* After parsing the configuration file we setup the core path one more time
+        * as the log file might have been set in the configuration and cores's
+        * path is by default basename(lp_logfile()).
+        */
+       dump_core_setup("winbindd");
 
        /* Initialise messaging system */
 
@@ -1260,11 +1274,12 @@ int main(int argc, char **argv, char **envp)
                exit(1);
        }
 
-       te = tevent_add_timer(winbind_event_context(), NULL, timeval_zero(),
-                             rescan_trusted_domains, NULL);
-       if (te == NULL) {
-               DEBUG(0, ("Could not trigger rescan_trusted_domains()\n"));
-               exit(1);
+       if (lp_allow_trusted_domains()) {
+               if (tevent_add_timer(winbind_event_context(), NULL, timeval_zero(),
+                             rescan_trusted_domains, NULL) == NULL) {
+                       DEBUG(0, ("Could not trigger rescan_trusted_domains()\n"));
+                       exit(1);
+               }
        }
 
        TALLOC_FREE(frame);