/*************************************************************************** load automatic printer services ***************************************************************************/ void load_printers(void) { if (!pcap_cache_loaded()) pcap_cache_reload(); add_auto_printers(); /* load all printcap printers */ if (lp_load_printers() && lp_servicenumber(PRINTERS_NAME) >= 0) pcap_printer_fn(lp_add_one_printer, NULL); }
void printing_subsystem_update(struct tevent_context *ev_ctx, struct messaging_context *msg_ctx, bool force) { if (background_lpq_updater_pid != -1) { if (pcap_cache_loaded()) { load_printers(ev_ctx, msg_ctx); } if (force) { /* Send a sighup to the background process. * this will force it to reload printers */ kill(background_lpq_updater_pid, SIGHUP); } return; } pcap_cache_reload(ev_ctx, msg_ctx, &delete_and_reload_printers); }
/** * @brief Purge stale printer shares and reload from pre-populated pcap cache. * * This function should normally only be called as a callback on a successful * pcap_cache_reload(), or on client enumeration. * * @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) { int n_services; int pnum; int snum; const char *pname; bool ok; time_t pcap_last_update; TALLOC_CTX *frame = talloc_stackframe(); ok = pcap_cache_loaded(&pcap_last_update); if (!ok) { DEBUG(1, ("pcap cache not loaded\n")); talloc_free(frame); return; } if (reload_last_pcap_time == pcap_last_update) { DEBUG(5, ("skipping printer reload, already up to date.\n")); talloc_free(frame); return; } reload_last_pcap_time = pcap_last_update; /* 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")); /* * 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; } /* skip no-printer services */ if (!snum_is_shared_printer(snum)) { continue; } pname = lp_printername(frame, snum); /* check printer, but avoid removing non-autoloaded printers */ if (lp_autoloaded(snum) && !pcap_printername_ok(pname)) { lp_killservice(snum); } } /* Make sure deleted printers are gone */ load_printers(ev, msg_ctx); talloc_free(frame); }
static bool spoolss_child_init(struct tevent_context *ev_ctx, int child_id, struct pf_worker_data *pf) { NTSTATUS status; struct rpc_srv_callbacks spoolss_cb; struct messaging_context *msg_ctx = messaging_init(NULL, ev_ctx); bool ok; status = reinit_after_fork(msg_ctx, ev_ctx, true); if (!NT_STATUS_IS_OK(status)) { DEBUG(0,("reinit_after_fork() failed\n")); smb_panic("reinit_after_fork() failed"); } prctl_set_comment("spoolssd-child"); spoolss_child_id = child_id; spoolss_reopen_logs(child_id); ok = spoolss_setup_chld_hup_handler(ev_ctx, msg_ctx, pf); if (!ok) { return false; } if (!serverid_register(messaging_server_id(msg_ctx), FLAG_MSG_GENERAL | FLAG_MSG_PRINT_GENERAL)) { return false; } if (!locking_init()) { return false; } messaging_register(msg_ctx, ev_ctx, MSG_SMB_CONF_UPDATED, smb_conf_updated); messaging_register(msg_ctx, ev_ctx, MSG_PREFORK_PARENT_EVENT, parent_ping); /* As soon as messaging is up check if pcap has been loaded already. * If so then we probably missed a message and should load_printers() * ourselves. If pcap has not been loaded yet, then ignore, we will get * a message as soon as the bq process completes the reload. */ if (pcap_cache_loaded(NULL)) { load_printers(ev_ctx, msg_ctx); } /* try to reinit rpc queues */ spoolss_cb.init = spoolss_init_cb; spoolss_cb.shutdown = spoolss_shutdown_cb; spoolss_cb.private_data = msg_ctx; status = rpc_winreg_init(NULL); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("Failed to register winreg rpc inteface! (%s)\n", nt_errstr(status))); return false; } status = rpc_spoolss_init(&spoolss_cb); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("Failed to register spoolss rpc inteface! (%s)\n", nt_errstr(status))); return false; } return true; }