s3:idmap_autorid: add an allocation range to autorid
[Samba/gebeck_regimport.git] / source3 / smbd / server_reload.c
blob0c2ea2c5b127d36d9a52949530a6f1bdb352c762
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"
34 /**
35 * @brief Purge stale printers and reload from pre-populated pcap cache.
37 * This function should normally only be called as a callback on a successful
38 * pcap_cache_reload() or after a MSG_PRINTER_CAP message is received.
40 * This function can cause DELETION of printers and drivers from our registry,
41 * so calling it on a failed pcap reload may REMOVE permanently all printers
42 * and drivers.
44 * @param[in] ev The event context.
46 * @param[in] msg_ctx The messaging context.
48 void delete_and_reload_printers(struct tevent_context *ev,
49 struct messaging_context *msg_ctx)
51 struct auth_session_info *session_info = NULL;
52 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
53 int snum;
54 int n_services = lp_numservices();
55 int pnum = lp_servicenumber(PRINTERS_NAME);
56 const char *pname;
57 NTSTATUS status;
58 bool skip = false;
60 SMB_ASSERT(pcap_cache_loaded());
61 DEBUG(10, ("reloading printer services from pcap cache\n"));
63 status = make_session_info_system(talloc_tos(), &session_info);
64 if (!NT_STATUS_IS_OK(status)) {
65 DEBUG(3, ("reload_printers: "
66 "Could not create system session_info\n"));
67 /* can't remove stale printers before we
68 * are fully initilized */
69 skip = true;
72 /* remove stale printers */
73 for (snum = 0; skip == false && snum < n_services; snum++) {
74 /* avoid removing PRINTERS_NAME or non-autoloaded printers */
75 if (snum == pnum || !(lp_snum_ok(snum) && lp_print_ok(snum) &&
76 lp_autoloaded(snum)))
77 continue;
79 pname = lp_printername(snum);
80 if (!pcap_printername_ok(pname)) {
81 DEBUG(3, ("removing stale printer %s\n", pname));
83 if (is_printer_published(session_info, session_info,
84 msg_ctx,
85 NULL, lp_servicename(snum),
86 NULL, &pinfo2)) {
87 nt_printer_publish(session_info,
88 session_info,
89 msg_ctx,
90 pinfo2,
91 DSPRINT_UNPUBLISH);
92 TALLOC_FREE(pinfo2);
94 nt_printer_remove(session_info, session_info, msg_ctx,
95 pname);
96 lp_killservice(snum);
100 load_printers(ev, msg_ctx);
102 TALLOC_FREE(session_info);
105 /****************************************************************************
106 Reload the services file.
107 **************************************************************************/
109 bool reload_services(struct messaging_context *msg_ctx, int smb_sock,
110 bool test)
112 bool ret;
114 if (lp_loaded()) {
115 char *fname = lp_configfile();
116 if (file_exist(fname) &&
117 !strcsequal(fname, get_dyn_CONFIGFILE())) {
118 set_dyn_CONFIGFILE(fname);
119 test = False;
123 reopen_logs();
125 if (test && !lp_file_list_changed())
126 return(True);
128 if (msg_ctx) {
129 lp_killunused(msg_ctx_to_sconn(msg_ctx), conn_snum_used);
130 } else {
131 lp_killunused(NULL, NULL);
134 ret = lp_load(get_dyn_CONFIGFILE(), False, False, True, True);
136 /* perhaps the config filename is now set */
137 if (!test)
138 reload_services(msg_ctx, smb_sock, True);
140 reopen_logs();
142 load_interfaces();
144 if (smb_sock != -1) {
145 set_socket_options(smb_sock,"SO_KEEPALIVE");
146 set_socket_options(smb_sock, lp_socket_options());
149 mangle_reset_cache();
150 reset_stat_cache();
152 /* this forces service parameters to be flushed */
153 set_current_service(NULL,0,True);
155 return(ret);