wafsamba: remove unused variable from copy_and_fix_python_path
[Samba.git] / source3 / smbd / server_reload.c
blob971c8b86efbd4c035153ccae784418dfe9b9e5da
1 /*
2 Unix SMB/CIFS implementation.
3 Main SMB server routines
4 Copyright (C) Andrew Tridgell 1992-1998
5 Copyright (C) Martin Pool 2002
6 Copyright (C) Jelmer Vernooij 2002-2003
7 Copyright (C) Volker Lendecke 1993-2007
8 Copyright (C) Jeremy Allison 1993-2007
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "includes.h"
25 #include "smbd/smbd.h"
26 #include "smbd/globals.h"
27 #include "nt_printing.h"
28 #include "printing/pcap.h"
29 #include "printing/load.h"
30 #include "auth.h"
31 #include "messages.h"
32 #include "lib/param/loadparm.h"
35 * The persistent pcap cache is populated by the background print process. Per
36 * client smbds should only reload their printer share inventories if this
37 * information has changed. Use reload_last_pcap_time to detect this.
39 static time_t reload_last_pcap_time = 0;
41 bool snum_is_shared_printer(int snum)
43 return (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum));
46 /**
47 * @brief Purge stale printer shares and reload from pre-populated pcap cache.
49 * This function should normally only be called as a callback on a successful
50 * pcap_cache_reload(), or on client enumeration.
52 * @param[in] ev The event context.
54 * @param[in] msg_ctx The messaging context.
56 void delete_and_reload_printers(struct tevent_context *ev,
57 struct messaging_context *msg_ctx)
59 int n_services;
60 int pnum;
61 int snum;
62 const char *pname;
63 bool ok;
64 time_t pcap_last_update;
65 TALLOC_CTX *frame = talloc_stackframe();
67 ok = pcap_cache_loaded(&pcap_last_update);
68 if (!ok) {
69 DEBUG(1, ("pcap cache not loaded\n"));
70 talloc_free(frame);
71 return;
74 if (reload_last_pcap_time == pcap_last_update) {
75 DEBUG(5, ("skipping printer reload, already up to date.\n"));
76 talloc_free(frame);
77 return;
79 reload_last_pcap_time = pcap_last_update;
81 /* Get pcap printers updated */
82 load_printers(ev, msg_ctx);
84 n_services = lp_numservices();
85 pnum = lp_servicenumber(PRINTERS_NAME);
87 DEBUG(10, ("reloading printer services from pcap cache\n"));
90 * Add default config for printers added to smb.conf file and remove
91 * stale printers
93 for (snum = 0; snum < n_services; snum++) {
94 /* avoid removing PRINTERS_NAME */
95 if (snum == pnum) {
96 continue;
99 /* skip no-printer services */
100 if (!snum_is_shared_printer(snum)) {
101 continue;
104 pname = lp_printername(frame, snum);
106 /* check printer, but avoid removing non-autoloaded printers */
107 if (lp_autoloaded(snum) && !pcap_printername_ok(pname)) {
108 lp_killservice(snum);
112 /* Make sure deleted printers are gone */
113 load_printers(ev, msg_ctx);
115 talloc_free(frame);
118 /****************************************************************************
119 Reload the services file.
120 **************************************************************************/
122 bool reload_services(struct smbd_server_connection *sconn,
123 bool (*snumused) (struct smbd_server_connection *, int),
124 bool test)
126 bool ret;
128 if (lp_loaded()) {
129 char *fname = lp_configfile(talloc_tos());
130 if (file_exist(fname) &&
131 !strcsequal(fname, get_dyn_CONFIGFILE())) {
132 set_dyn_CONFIGFILE(fname);
133 test = False;
135 TALLOC_FREE(fname);
138 reopen_logs();
140 if (test && !lp_file_list_changed())
141 return(True);
143 lp_killunused(sconn, snumused);
145 ret = lp_load(get_dyn_CONFIGFILE(),
146 false, /* global only */
147 false, /* save defaults */
148 true, /* add_ipc */
149 true); /* initialize globals */
151 /* perhaps the config filename is now set */
152 if (!test) {
153 reload_services(sconn, snumused, true);
156 reopen_logs();
158 load_interfaces();
160 if (sconn != NULL) {
161 set_socket_options(sconn->sock, "SO_KEEPALIVE");
162 set_socket_options(sconn->sock, lp_socket_options());
165 mangle_reset_cache();
166 reset_stat_cache();
168 /* this forces service parameters to be flushed */
169 set_current_service(NULL,0,True);
171 return(ret);