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/>.
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"
32 #include "lib/param/loadparm.h"
34 static bool snum_is_shared_printer(int snum
)
36 return (lp_browseable(snum
) && lp_snum_ok(snum
) && lp_print_ok(snum
));
40 * @brief Purge stale printers and reload from pre-populated pcap cache.
42 * This function should normally only be called as a callback on a successful
43 * pcap_cache_reload() or after a MSG_PRINTER_CAP message is received.
45 * This function can cause DELETION of printers and drivers from our registry,
46 * so calling it on a failed pcap reload may REMOVE permanently all printers
49 * @param[in] ev The event context.
51 * @param[in] msg_ctx The messaging context.
53 void delete_and_reload_printers(struct tevent_context
*ev
,
54 struct messaging_context
*msg_ctx
)
56 struct auth_session_info
*session_info
= NULL
;
57 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
65 /* Get pcap printers updated */
66 load_printers(ev
, msg_ctx
);
68 n_services
= lp_numservices();
69 pnum
= lp_servicenumber(PRINTERS_NAME
);
71 DEBUG(10, ("reloading printer services from pcap cache\n"));
73 status
= make_session_info_system(talloc_tos(), &session_info
);
74 if (!NT_STATUS_IS_OK(status
)) {
75 DEBUG(3, ("reload_printers: "
76 "Could not create system session_info\n"));
77 /* can't remove stale printers before we
78 * are fully initilized */
83 * Add default config for printers added to smb.conf file and remove
86 for (snum
= 0; snum
< n_services
; snum
++) {
87 /* avoid removing PRINTERS_NAME */
92 /* skip no-printer services */
93 if (!snum_is_shared_printer(snum
)) {
97 sname
= lp_const_servicename(snum
);
98 pname
= lp_printername(snum
);
100 /* check printer, but avoid removing non-autoloaded printers */
101 if (!pcap_printername_ok(pname
) && lp_autoloaded(snum
)) {
102 DEBUG(3, ("removing stale printer %s\n", pname
));
104 if (is_printer_published(session_info
, session_info
,
106 NULL
, lp_servicename(snum
),
108 nt_printer_publish(session_info
,
115 nt_printer_remove(session_info
, session_info
, msg_ctx
,
117 lp_killservice(snum
);
119 DEBUG(8, ("Adding default registry entry for printer "
120 "[%s], if it doesn't exist.\n", sname
));
121 nt_printer_add(session_info
, session_info
, msg_ctx
,
126 /* Make sure deleted printers are gone */
127 load_printers(ev
, msg_ctx
);
129 TALLOC_FREE(session_info
);
132 /****************************************************************************
133 Reload the services file.
134 **************************************************************************/
136 bool reload_services(struct smbd_server_connection
*sconn
,
137 bool (*snumused
) (struct smbd_server_connection
*, int),
143 char *fname
= lp_configfile();
144 if (file_exist(fname
) &&
145 !strcsequal(fname
, get_dyn_CONFIGFILE())) {
146 set_dyn_CONFIGFILE(fname
);
153 if (test
&& !lp_file_list_changed())
156 lp_killunused(sconn
, snumused
);
158 ret
= lp_load(get_dyn_CONFIGFILE(),
159 false, /* global only */
160 false, /* save defaults */
162 true); /* initialize globals */
164 /* perhaps the config filename is now set */
166 reload_services(sconn
, snumused
, true);
174 set_socket_options(sconn
->sock
, "SO_KEEPALIVE");
175 set_socket_options(sconn
->sock
, lp_socket_options());
178 mangle_reset_cache();
181 /* this forces service parameters to be flushed */
182 set_current_service(NULL
,0,True
);