| 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/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 |
|
|---|
| 33 | /****************************************************************************
|
|---|
| 34 | purge stale printers and reload from pre-populated pcap cache
|
|---|
| 35 | **************************************************************************/
|
|---|
| 36 | void reload_printers(struct tevent_context *ev,
|
|---|
| 37 | struct messaging_context *msg_ctx)
|
|---|
| 38 | {
|
|---|
| 39 | int n_services;
|
|---|
| 40 | int pnum;
|
|---|
| 41 | int snum;
|
|---|
| 42 | const char *pname;
|
|---|
| 43 |
|
|---|
| 44 | n_services = lp_numservices();
|
|---|
| 45 | pnum = lp_servicenumber(PRINTERS_NAME);
|
|---|
| 46 |
|
|---|
| 47 | DEBUG(10, ("reloading printer services from pcap cache\n"));
|
|---|
| 48 |
|
|---|
| 49 | /*
|
|---|
| 50 | * Add default config for printers added to smb.conf file and remove
|
|---|
| 51 | * stale printers
|
|---|
| 52 | */
|
|---|
| 53 | for (snum = 0; snum < n_services; snum++) {
|
|---|
| 54 | /* avoid removing PRINTERS_NAME */
|
|---|
| 55 | if (snum == pnum) {
|
|---|
| 56 | continue;
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | /* skip no-printer services */
|
|---|
| 60 | if (!(lp_snum_ok(snum) && lp_print_ok(snum))) {
|
|---|
| 61 | continue;
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | pname = lp_printername(snum);
|
|---|
| 65 |
|
|---|
| 66 | /* check printer, but avoid removing non-autoloaded printers */
|
|---|
| 67 | if (lp_autoloaded(snum) && !pcap_printername_ok(pname)) {
|
|---|
| 68 | DEBUG(3, ("removing stale printer %s\n", pname));
|
|---|
| 69 | lp_killservice(snum);
|
|---|
| 70 | }
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | /* Make sure deleted printers are gone */
|
|---|
| 74 | load_printers(ev, msg_ctx);
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | /****************************************************************************
|
|---|
| 78 | purge stale printers and reload from pre-populated pcap cache
|
|---|
| 79 | **************************************************************************/
|
|---|
| 80 | void reload_printers_full(struct tevent_context *ev,
|
|---|
| 81 | struct messaging_context *msg_ctx)
|
|---|
| 82 | {
|
|---|
| 83 | struct auth_serversupplied_info *session_info = NULL;
|
|---|
| 84 | int n_services;
|
|---|
| 85 | int pnum;
|
|---|
| 86 | int snum;
|
|---|
| 87 | const char *pname;
|
|---|
| 88 | const char *sname;
|
|---|
| 89 | NTSTATUS status;
|
|---|
| 90 |
|
|---|
| 91 | n_services = lp_numservices();
|
|---|
| 92 | pnum = lp_servicenumber(PRINTERS_NAME);
|
|---|
| 93 |
|
|---|
| 94 | status = make_session_info_system(talloc_new(NULL), &session_info);
|
|---|
| 95 | if (!NT_STATUS_IS_OK(status)) {
|
|---|
| 96 | DEBUG(3, ("Could not create system session_info\n"));
|
|---|
| 97 | /* can't remove stale printers before we
|
|---|
| 98 | * are fully initilized */
|
|---|
| 99 | return;
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | /*
|
|---|
| 103 | * Add default config for printers added to smb.conf file and remove
|
|---|
| 104 | * stale printers
|
|---|
| 105 | */
|
|---|
| 106 | for (snum = 0; snum < n_services; snum++) {
|
|---|
| 107 | /* avoid removing PRINTERS_NAME */
|
|---|
| 108 | if (snum == pnum) {
|
|---|
| 109 | continue;
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | /* skip no-printer services */
|
|---|
| 113 | if (!(lp_snum_ok(snum) && lp_print_ok(snum))) {
|
|---|
| 114 | continue;
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | sname = lp_const_servicename(snum);
|
|---|
| 118 | pname = lp_printername(snum);
|
|---|
| 119 |
|
|---|
| 120 | /* check printer, but avoid removing non-autoloaded printers */
|
|---|
| 121 | if (lp_autoloaded(snum) && !pcap_printername_ok(pname)) {
|
|---|
| 122 | struct spoolss_PrinterInfo2 *pinfo2 = NULL;
|
|---|
| 123 | if (is_printer_published(session_info, session_info,
|
|---|
| 124 | msg_ctx,
|
|---|
| 125 | NULL,
|
|---|
| 126 | lp_servicename(snum),
|
|---|
| 127 | &pinfo2)) {
|
|---|
| 128 | nt_printer_publish(session_info,
|
|---|
| 129 | session_info,
|
|---|
| 130 | msg_ctx,
|
|---|
| 131 | pinfo2,
|
|---|
| 132 | DSPRINT_UNPUBLISH);
|
|---|
| 133 | TALLOC_FREE(pinfo2);
|
|---|
| 134 | }
|
|---|
| 135 | nt_printer_remove(session_info, session_info, msg_ctx,
|
|---|
| 136 | pname);
|
|---|
| 137 | } else {
|
|---|
| 138 | DEBUG(8, ("Adding default registry entry for printer "
|
|---|
| 139 | "[%s], if it doesn't exist.\n", sname));
|
|---|
| 140 | nt_printer_add(session_info, session_info, msg_ctx,
|
|---|
| 141 | sname);
|
|---|
| 142 | }
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | /* finally, purge old snums */
|
|---|
| 146 | reload_printers(ev, msg_ctx);
|
|---|
| 147 |
|
|---|
| 148 | TALLOC_FREE(session_info);
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | /****************************************************************************
|
|---|
| 152 | Reload the services file.
|
|---|
| 153 | **************************************************************************/
|
|---|
| 154 |
|
|---|
| 155 | bool reload_services(struct messaging_context *msg_ctx, int smb_sock,
|
|---|
| 156 | bool test)
|
|---|
| 157 | {
|
|---|
| 158 | bool ret;
|
|---|
| 159 |
|
|---|
| 160 | if (lp_loaded()) {
|
|---|
| 161 | char *fname = lp_configfile();
|
|---|
| 162 | if (file_exist(fname) &&
|
|---|
| 163 | !strcsequal(fname, get_dyn_CONFIGFILE())) {
|
|---|
| 164 | set_dyn_CONFIGFILE(fname);
|
|---|
| 165 | test = False;
|
|---|
| 166 | }
|
|---|
| 167 | TALLOC_FREE(fname);
|
|---|
| 168 | }
|
|---|
| 169 |
|
|---|
| 170 | reopen_logs();
|
|---|
| 171 |
|
|---|
| 172 | if (test && !lp_file_list_changed())
|
|---|
| 173 | return(True);
|
|---|
| 174 |
|
|---|
| 175 | lp_killunused(conn_snum_used);
|
|---|
| 176 |
|
|---|
| 177 | ret = lp_load(get_dyn_CONFIGFILE(), False, False, True, True);
|
|---|
| 178 |
|
|---|
| 179 | /* perhaps the config filename is now set */
|
|---|
| 180 | if (!test)
|
|---|
| 181 | reload_services(msg_ctx, smb_sock, True);
|
|---|
| 182 |
|
|---|
| 183 | reopen_logs();
|
|---|
| 184 |
|
|---|
| 185 | load_interfaces();
|
|---|
| 186 |
|
|---|
| 187 | if (smb_sock != -1) {
|
|---|
| 188 | set_socket_options(smb_sock,"SO_KEEPALIVE");
|
|---|
| 189 | set_socket_options(smb_sock, lp_socket_options());
|
|---|
| 190 | }
|
|---|
| 191 |
|
|---|
| 192 | mangle_reset_cache();
|
|---|
| 193 | reset_stat_cache();
|
|---|
| 194 |
|
|---|
| 195 | /* this forces service parameters to be flushed */
|
|---|
| 196 | set_current_service(NULL,0,True);
|
|---|
| 197 |
|
|---|
| 198 | return(ret);
|
|---|
| 199 | }
|
|---|