X-Git-Url: http://git.samba.org/?a=blobdiff_plain;f=source3%2Fsmbd%2Fserver_reload.c;h=1d6f9c2911ff0581fd39d527ab2a6ab5e05764f2;hb=002d1a44672c9b3247a68a86899ce6644b696a48;hp=84213ae0e802e4204bb7e19858fe12638740e258;hpb=b2af281e508194d9548ea1119c19ee96a0dd1f0a;p=obnox%2Fsamba%2Fsamba-obnox.git diff --git a/source3/smbd/server_reload.c b/source3/smbd/server_reload.c index 84213ae0e80..1d6f9c2911f 100644 --- a/source3/smbd/server_reload.c +++ b/source3/smbd/server_reload.c @@ -24,29 +24,50 @@ #include "includes.h" #include "smbd/smbd.h" #include "smbd/globals.h" -#include "librpc/gen_ndr/messaging.h" #include "nt_printing.h" #include "printing/pcap.h" #include "printing/load.h" #include "auth.h" #include "messages.h" +#include "lib/param/loadparm.h" -/**************************************************************************** - purge stale printers and reload from pre-populated pcap cache -**************************************************************************/ -void reload_printers(struct tevent_context *ev, - struct messaging_context *msg_ctx) +static bool snum_is_shared_printer(int snum) +{ + return (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum)); +} + +/** + * @brief Purge stale printers and reload from pre-populated pcap cache. + * + * This function should normally only be called as a callback on a successful + * pcap_cache_reload() or after a MSG_PRINTER_CAP message is received. + * + * This function can cause DELETION of printers and drivers from our registry, + * so calling it on a failed pcap reload may REMOVE permanently all printers + * and drivers. + * + * @param[in] ev The event context. + * + * @param[in] msg_ctx The messaging context. + */ +void delete_and_reload_printers(struct tevent_context *ev, + struct messaging_context *msg_ctx) { - struct auth_serversupplied_info *session_info = NULL; + struct auth_session_info *session_info = NULL; struct spoolss_PrinterInfo2 *pinfo2 = NULL; + int n_services; + int pnum; int snum; - int n_services = lp_numservices(); - int pnum = lp_servicenumber(PRINTERS_NAME); const char *pname; + const char *sname; NTSTATUS status; - bool skip = false; - SMB_ASSERT(pcap_cache_loaded()); + /* Get pcap printers updated */ + load_printers(ev, msg_ctx); + + n_services = lp_numservices(); + pnum = lp_servicenumber(PRINTERS_NAME); + DEBUG(10, ("reloading printer services from pcap cache\n")); status = make_session_info_system(talloc_tos(), &session_info); @@ -55,24 +76,37 @@ void reload_printers(struct tevent_context *ev, "Could not create system session_info\n")); /* can't remove stale printers before we * are fully initilized */ - skip = true; + return; } - /* remove stale printers */ - for (snum = 0; skip == false && snum < n_services; snum++) { - /* avoid removing PRINTERS_NAME or non-autoloaded printers */ - if (snum == pnum || !(lp_snum_ok(snum) && lp_print_ok(snum) && - lp_autoloaded(snum))) + /* + * Add default config for printers added to smb.conf file and remove + * stale printers + */ + for (snum = 0; snum < n_services; snum++) { + /* avoid removing PRINTERS_NAME */ + if (snum == pnum) { continue; + } - pname = lp_printername(snum); - if (!pcap_printername_ok(pname)) { + /* skip no-printer services */ + if (!snum_is_shared_printer(snum)) { + continue; + } + + sname = lp_const_servicename(snum); + pname = lp_printername(session_info, snum); + + /* check printer, but avoid removing non-autoloaded printers */ + if (lp_autoloaded(snum) && !pcap_printername_ok(pname)) { DEBUG(3, ("removing stale printer %s\n", pname)); if (is_printer_published(session_info, session_info, msg_ctx, - NULL, lp_servicename(snum), - NULL, &pinfo2)) { + NULL, + lp_servicename(session_info, + snum), + &pinfo2)) { nt_printer_publish(session_info, session_info, msg_ctx, @@ -83,9 +117,15 @@ void reload_printers(struct tevent_context *ev, nt_printer_remove(session_info, session_info, msg_ctx, pname); lp_killservice(snum); + } else { + DEBUG(8, ("Adding default registry entry for printer " + "[%s], if it doesn't exist.\n", sname)); + nt_printer_add(session_info, session_info, msg_ctx, + sname); } } + /* Make sure deleted printers are gone */ load_printers(ev, msg_ctx); TALLOC_FREE(session_info); @@ -95,18 +135,20 @@ void reload_printers(struct tevent_context *ev, Reload the services file. **************************************************************************/ -bool reload_services(struct messaging_context *msg_ctx, int smb_sock, +bool reload_services(struct smbd_server_connection *sconn, + bool (*snumused) (struct smbd_server_connection *, int), bool test) { bool ret; if (lp_loaded()) { - char *fname = lp_configfile(); + char *fname = lp_configfile(talloc_tos()); if (file_exist(fname) && !strcsequal(fname, get_dyn_CONFIGFILE())) { set_dyn_CONFIGFILE(fname); test = False; } + TALLOC_FREE(fname); } reopen_logs(); @@ -114,21 +156,26 @@ bool reload_services(struct messaging_context *msg_ctx, int smb_sock, if (test && !lp_file_list_changed()) return(True); - lp_killunused(conn_snum_used); + lp_killunused(sconn, snumused); - ret = lp_load(get_dyn_CONFIGFILE(), False, False, True, True); + ret = lp_load(get_dyn_CONFIGFILE(), + false, /* global only */ + false, /* save defaults */ + true, /* add_ipc */ + true); /* initialize globals */ /* perhaps the config filename is now set */ - if (!test) - reload_services(msg_ctx, smb_sock, True); + if (!test) { + reload_services(sconn, snumused, true); + } reopen_logs(); load_interfaces(); - if (smb_sock != -1) { - set_socket_options(smb_sock,"SO_KEEPALIVE"); - set_socket_options(smb_sock, lp_socket_options()); + if (sconn != NULL) { + set_socket_options(sconn->sock, "SO_KEEPALIVE"); + set_socket_options(sconn->sock, lp_socket_options()); } mangle_reset_cache(); @@ -139,12 +186,3 @@ bool reload_services(struct messaging_context *msg_ctx, int smb_sock, return(ret); } - -/**************************************************************************** - Notify smbds of new printcap data -**************************************************************************/ -void reload_pcap_change_notify(struct tevent_context *ev, - struct messaging_context *msg_ctx) -{ - message_send_all(msg_ctx, MSG_PRINTER_PCAP, NULL, 0, NULL); -}