s3: Lift the smbd_messaging_context from is_printer_published
[nivanova/samba-autobuild/.git] / source3 / smbd / server_reload.c
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
9
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.
14
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.
19
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/>.
22 */
23
24 #include "includes.h"
25 #include "smbd/globals.h"
26 #include "librpc/gen_ndr/messaging.h"
27 #include "nt_printing.h"
28
29 /****************************************************************************
30  Reload printers
31 **************************************************************************/
32 void reload_printers(void)
33 {
34         struct auth_serversupplied_info *server_info = NULL;
35         struct spoolss_PrinterInfo2 *pinfo2 = NULL;
36         int snum;
37         int n_services = lp_numservices();
38         int pnum = lp_servicenumber(PRINTERS_NAME);
39         const char *pname;
40         NTSTATUS status;
41         bool skip = false;
42
43         pcap_cache_reload();
44
45         status = make_server_info_system(talloc_tos(), &server_info);
46         if (!NT_STATUS_IS_OK(status)) {
47                 DEBUG(0, ("reload_printers: "
48                           "Could not create system server_info\n"));
49                 /* can't remove stale printers before we
50                  * are fully initilized */
51                 skip = true;
52         }
53
54         /* remove stale printers */
55         for (snum = 0; skip == false && snum < n_services; snum++) {
56                 /* avoid removing PRINTERS_NAME or non-autoloaded printers */
57                 if (snum == pnum || !(lp_snum_ok(snum) && lp_print_ok(snum) &&
58                                       lp_autoloaded(snum)))
59                         continue;
60
61                 pname = lp_printername(snum);
62                 if (!pcap_printername_ok(pname)) {
63                         DEBUG(3, ("removing stale printer %s\n", pname));
64
65                         if (is_printer_published(server_info, server_info,
66                                                  smbd_messaging_context(),
67                                                  NULL, lp_servicename(snum),
68                                                  NULL, &pinfo2)) {
69                                 nt_printer_publish(server_info,
70                                                    server_info,
71                                                    smbd_messaging_context(),
72                                                    pinfo2,
73                                                    DSPRINT_UNPUBLISH);
74                                 TALLOC_FREE(pinfo2);
75                         }
76                         nt_printer_remove(server_info, server_info,
77                                           smbd_messaging_context(), pname);
78                         lp_killservice(snum);
79                 }
80         }
81
82         load_printers();
83
84         TALLOC_FREE(server_info);
85 }
86
87 /****************************************************************************
88  Reload the services file.
89 **************************************************************************/
90
91 bool reload_services(bool test)
92 {
93         bool ret;
94
95         if (lp_loaded()) {
96                 char *fname = lp_configfile();
97                 if (file_exist(fname) &&
98                     !strcsequal(fname, get_dyn_CONFIGFILE())) {
99                         set_dyn_CONFIGFILE(fname);
100                         test = False;
101                 }
102         }
103
104         reopen_logs();
105
106         if (test && !lp_file_list_changed())
107                 return(True);
108
109         lp_killunused(conn_snum_used);
110
111         ret = lp_load(get_dyn_CONFIGFILE(), False, False, True, True);
112
113         reload_printers();
114
115         /* perhaps the config filename is now set */
116         if (!test)
117                 reload_services(True);
118
119         reopen_logs();
120
121         load_interfaces();
122
123         if (smbd_server_fd() != -1) {
124                 set_socket_options(smbd_server_fd(),"SO_KEEPALIVE");
125                 set_socket_options(smbd_server_fd(), lp_socket_options());
126         }
127
128         mangle_reset_cache();
129         reset_stat_cache();
130
131         /* this forces service parameters to be flushed */
132         set_current_service(NULL,0,True);
133
134         return(ret);
135 }