s3-printing: Initiate pcap reload from parent smbd
[Samba.git] / source3 / smbd / server_reload.c
blobbdca29d0bf90f44d6a14b128aa4e9e8a1c61c9f8
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/globals.h"
26 #include "librpc/gen_ndr/messaging.h"
27 #include "nt_printing.h"
28 #include "printing/pcap.h"
30 /****************************************************************************
31 purge stale printers and reload from pre-populated pcap cache
32 **************************************************************************/
33 void reload_printers(struct tevent_context *ev,
34 struct messaging_context *msg_ctx)
36 struct auth_serversupplied_info *server_info = NULL;
37 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
38 int snum;
39 int n_services = lp_numservices();
40 int pnum = lp_servicenumber(PRINTERS_NAME);
41 const char *pname;
42 NTSTATUS status;
43 bool skip = false;
45 SMB_ASSERT(pcap_cache_loaded());
46 DEBUG(10, ("reloading printer services from pcap cache\n"));
48 status = make_server_info_system(talloc_tos(), &server_info);
49 if (!NT_STATUS_IS_OK(status)) {
50 DEBUG(3, ("reload_printers: "
51 "Could not create system server_info\n"));
52 /* can't remove stale printers before we
53 * are fully initilized */
54 skip = true;
57 /* remove stale printers */
58 for (snum = 0; skip == false && snum < n_services; snum++) {
59 /* avoid removing PRINTERS_NAME or non-autoloaded printers */
60 if (snum == pnum || !(lp_snum_ok(snum) && lp_print_ok(snum) &&
61 lp_autoloaded(snum)))
62 continue;
64 pname = lp_printername(snum);
65 if (!pcap_printername_ok(pname)) {
66 DEBUG(3, ("removing stale printer %s\n", pname));
68 if (is_printer_published(server_info, server_info,
69 msg_ctx,
70 NULL, lp_servicename(snum),
71 NULL, &pinfo2)) {
72 nt_printer_publish(server_info,
73 server_info,
74 msg_ctx,
75 pinfo2,
76 DSPRINT_UNPUBLISH);
77 TALLOC_FREE(pinfo2);
79 nt_printer_remove(server_info, server_info, msg_ctx,
80 pname);
81 lp_killservice(snum);
85 load_printers(ev, msg_ctx);
87 TALLOC_FREE(server_info);
90 /****************************************************************************
91 Reload the services file.
92 **************************************************************************/
94 bool reload_services(struct messaging_context *msg_ctx, int smb_sock,
95 bool test)
97 bool ret;
99 if (lp_loaded()) {
100 char *fname = lp_configfile();
101 if (file_exist(fname) &&
102 !strcsequal(fname, get_dyn_CONFIGFILE())) {
103 set_dyn_CONFIGFILE(fname);
104 test = False;
108 reopen_logs();
110 if (test && !lp_file_list_changed())
111 return(True);
113 lp_killunused(conn_snum_used);
115 ret = lp_load(get_dyn_CONFIGFILE(), False, False, True, True);
117 /* perhaps the config filename is now set */
118 if (!test)
119 reload_services(msg_ctx, smb_sock, True);
121 reopen_logs();
123 load_interfaces();
125 if (smb_sock != -1) {
126 set_socket_options(smb_sock,"SO_KEEPALIVE");
127 set_socket_options(smb_sock, lp_socket_options());
130 mangle_reset_cache();
131 reset_stat_cache();
133 /* this forces service parameters to be flushed */
134 set_current_service(NULL,0,True);
136 return(ret);
139 /****************************************************************************
140 Notify smbds of new printcap data
141 **************************************************************************/
142 void reload_pcap_change_notify(struct tevent_context *ev,
143 struct messaging_context *msg_ctx)
145 message_send_all(msg_ctx, MSG_PRINTER_PCAP, NULL, 0, NULL);