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