s3-smbd: Added a function to setup rpc services.
[idra/samba.git] / source3 / smbd / process.c
index a1aed809829ea8e339132f7ae29d7dd893bef6ed..75bd7708785f0f445a203951aadc4f25125ce325 100644 (file)
@@ -943,6 +943,9 @@ static void smbd_sig_hup_handler(struct tevent_context *ev,
        change_to_root_user();
        DEBUG(1,("Reloading services after SIGHUP\n"));
        reload_services(msg_ctx, smbd_server_conn->sock, False);
+       if (am_parent) {
+               pcap_cache_reload(ev, msg_ctx, &reload_pcap_change_notify);
+       }
 }
 
 void smbd_setup_sig_hup_handler(struct tevent_context *ev,
@@ -960,7 +963,7 @@ void smbd_setup_sig_hup_handler(struct tevent_context *ev,
 static NTSTATUS smbd_server_connection_loop_once(struct smbd_server_connection *conn)
 {
        fd_set r_fds, w_fds;
-       int selrtn = 0;
+       int selrtn;
        struct timeval to;
        int maxfd = 0;
 
@@ -979,16 +982,11 @@ static NTSTATUS smbd_server_connection_loop_once(struct smbd_server_connection *
         * select for longer than it would take to wait for them.
         */
 
-       {
-               struct timeval now;
-               GetTimeOfDay(&now);
-
-               event_add_to_select_args(smbd_event_context(), &now,
-                                        &r_fds, &w_fds, &to, &maxfd);
-       }
+       event_add_to_select_args(smbd_event_context(),
+                                &r_fds, &w_fds, &to, &maxfd);
 
        /* Process a signal and timed events now... */
-       if (run_events(smbd_event_context(), &selrtn, NULL, NULL)) {
+       if (run_events(smbd_event_context(), 0, NULL, NULL)) {
                return NT_STATUS_RETRY;
        }
 
@@ -1003,25 +1001,15 @@ static NTSTATUS smbd_server_connection_loop_once(struct smbd_server_connection *
                errno = sav;
        }
 
-       /* Check if error */
-       if (selrtn == -1) {
-               if (errno == EINTR)
-                       return NT_STATUS_RETRY;
-               else
-                       /* Maybe the socket is dead? */
-                       return map_nt_error_from_unix(errno);
+       if (selrtn == -1 && errno != EINTR) {
+               return map_nt_error_from_unix(errno);
        }
 
-       /* Process events until all available fds have been handled.
-        * This allows for fair round-robin handling of all available fds
-        * on each select() wakeup, while still maintaining responsiveness
-        * by re-checking for signal and timed events between the handling
-        * of each ready fd. */
-       do {
-               run_events(smbd_event_context(), &selrtn, &r_fds, &w_fds);
-       } while (selrtn > 0);
+       if (run_events(smbd_event_context(), selrtn, &r_fds, &w_fds)) {
+               return NT_STATUS_RETRY;
+       }
 
-       /* Processed all fds or timed out */
+       /* Did we timeout ? */
        if (selrtn == 0) {
                return NT_STATUS_RETRY;
        }
@@ -2041,8 +2029,8 @@ void chain_reply(struct smb_request *req)
                 * Update smb headers where subsequent chained commands
                 * may have updated them.
                 */
-               SCVAL(req->chain_outbuf, smb_tid, CVAL(req->outbuf, smb_tid));
-               SCVAL(req->chain_outbuf, smb_uid, CVAL(req->outbuf, smb_uid));
+               SSVAL(req->chain_outbuf, smb_tid, SVAL(req->outbuf, smb_tid));
+               SSVAL(req->chain_outbuf, smb_uid, SVAL(req->outbuf, smb_uid));
 
                if (!smb_splice_chain(&req->chain_outbuf,
                                      CVAL(req->outbuf, smb_com),
@@ -2227,47 +2215,15 @@ void chain_reply(struct smb_request *req)
 
 static void check_reload(struct smbd_server_connection *sconn, time_t t)
 {
-       time_t printcap_cache_time = (time_t)lp_printcap_cache_time();
 
-       if(last_smb_conf_reload_time == 0) {
+       if (last_smb_conf_reload_time == 0) {
                last_smb_conf_reload_time = t;
-               /* Our printing subsystem might not be ready at smbd start up.
-                  Then no printer is available till the first printers check
-                  is performed.  A lower initial interval circumvents this. */
-               if ( printcap_cache_time > 60 )
-                       last_printer_reload_time = t - printcap_cache_time + 60;
-               else
-                       last_printer_reload_time = t;
-       }
-
-       if (mypid != getpid()) { /* First time or fork happened meanwhile */
-               /* randomize over 60 second the printcap reload to avoid all
-                * process hitting cupsd at the same time */
-               int time_range = 60;
-
-               last_printer_reload_time += random() % time_range;
-               mypid = getpid();
        }
 
        if (t >= last_smb_conf_reload_time+SMBD_RELOAD_CHECK) {
                reload_services(sconn->msg_ctx, sconn->sock, True);
                last_smb_conf_reload_time = t;
        }
-
-       /* 'printcap cache time = 0' disable the feature */
-
-       if ( printcap_cache_time != 0 )
-       { 
-               /* see if it's time to reload or if the clock has been set back */
-
-               if ( (t >= last_printer_reload_time+printcap_cache_time) 
-                       || (t-last_printer_reload_time  < 0) ) 
-               {
-                       DEBUG( 3,( "Printcap cache time expired.\n"));
-                       reload_printers(sconn->msg_ctx);
-                       last_printer_reload_time = t;
-               }
-       }
 }
 
 static bool fd_is_readable(int fd)
@@ -2497,13 +2453,16 @@ static bool housekeeping_fn(const struct timeval *now, void *private_data)
 {
        struct smbd_server_connection *sconn = talloc_get_type_abort(
                private_data, struct smbd_server_connection);
+
+       DEBUG(5, ("housekeeping\n"));
+
        change_to_root_user();
 
        /* update printer queue caches if necessary */
        update_monitored_printq_cache(sconn->msg_ctx);
 
        /* check if we need to reload services */
-       check_reload(sconn, time(NULL));
+       check_reload(sconn, time_mono(NULL));
 
        /* Change machine password if neccessary. */
        attempt_machine_password_change();
@@ -2946,7 +2905,6 @@ void smbd_process(struct smbd_server_connection *sconn)
        int ret;
 
        if (lp_maxprotocol() == PROTOCOL_SMB2 &&
-           lp_security() != SEC_SHARE &&
            !lp_async_smb_echo_handler()) {
                /*
                 * We're not making the desion here,
@@ -3110,7 +3068,7 @@ void smbd_process(struct smbd_server_connection *sconn)
        }
 
        if (!(event_add_idle(smbd_event_context(), NULL,
-                            timeval_set(SMBD_SELECT_TIMEOUT, 0),
+                            timeval_set(SMBD_HOUSEKEEPING_INTERVAL, 0),
                             "housekeeping", housekeeping_fn, sconn))) {
                DEBUG(0, ("Could not add housekeeping event\n"));
                exit(1);