Example #1
0
void reload_printers(void)
{
	int snum;
	int n_services = lp_numservices();
	int pnum = lp_servicenumber(PRINTERS_NAME);
	const char *pname;

	pcap_cache_reload();

	/* remove stale printers */
	for (snum = 0; 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)))
			continue;

		pname = lp_printername(snum);
		if (!pcap_printername_ok(pname)) {
			DEBUG(3, ("removing stale printer %s\n", pname));

			if (is_printer_published(NULL, snum, NULL))
				nt_printer_publish(NULL, snum, SPOOL_DS_UNPUBLISH);
			del_a_printer(pname);
			lp_killservice(snum);
		}
	}

	load_printers();
}
Example #2
0
int main(int argc, char *argv[])
{
   setup_logging(argv[0],True);

   printf("NOTICE: This program is now deprecated and will be removed \n");
   printf("in a future Samba release.\n\n");

   if (argc != 2)
      printf("Usage: testprns printername\n");
   else
   {
      dbf = x_fopen("test.log", O_WRONLY|O_CREAT|O_TRUNC, 0644);
      if (dbf == NULL) {
         printf("Unable to open logfile.\n");
      } else {
         DEBUGLEVEL = 3;
         printf("Looking for printer %s\n", argv[1]);
	load_printers();
         if (!pcap_printername_ok(argv[1]))
            printf("Printer name %s is not valid.\n", argv[1]);
         else
            printf("Printer name %s is valid.\n", argv[1]);
         x_fclose(dbf);
      }
   }
   return (0);
}
Example #3
0
static void update_conf(struct tevent_context *ev,
			struct messaging_context *msg)
{
	change_to_root_user();
	lp_load(get_dyn_CONFIGFILE(), true, false, false, true);
	load_printers(ev, msg);

	spoolss_reopen_logs(spoolss_child_id);
	if (spoolss_child_id == 0) {
		pfh_daemon_config(DAEMON_NAME,
				  &pf_spoolss_cfg,
				  &default_pf_spoolss_cfg);
		pfh_manage_pool(ev, msg, &pf_spoolss_cfg, spoolss_pool);
	}
}
Example #4
0
BOOL reload_services(BOOL test)
{
	BOOL ret;
	
	if (lp_loaded()) {
		pstring fname;
		pstrcpy(fname,lp_configfile());
		if (file_exist(fname, NULL) &&
		    !strcsequal(fname, dyn_CONFIGFILE)) {
			pstrcpy(dyn_CONFIGFILE, fname);
			test = False;
		}
	}

	reopen_logs();

	if (test && !lp_file_list_changed())
		return(True);

	lp_killunused(conn_snum_used);
	
	ret = lp_load(dyn_CONFIGFILE, False, False, True);

	load_printers();

	/* perhaps the config filename is now set */
	if (!test)
		reload_services(True);

	reopen_logs();

	load_interfaces();

	{
		if (smbd_server_fd() != -1) {      
			set_socket_options(smbd_server_fd(),"SO_KEEPALIVE");
			set_socket_options(smbd_server_fd(), user_socket_options);
		}
	}

	mangle_reset_cache();
	reset_stat_cache();

	/* this forces service parameters to be flushed */
	set_current_service(NULL,True);

	return (ret);
}
Example #5
0
static void spoolss_chld_sig_hup_handler(struct tevent_context *ev,
					 struct tevent_signal *se,
					 int signum,
					 int count,
					 void *siginfo,
					 void *pvt)
{
	struct messaging_context *msg_ctx;

	msg_ctx = talloc_get_type_abort(pvt, struct messaging_context);

	change_to_root_user();
	DEBUG(1,("Reloading printers after SIGHUP\n"));
	load_printers(ev, msg_ctx);
	spoolss_reopen_logs(spoolss_child_id);
}
Example #6
0
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);
}
Example #7
0
/****************************************************************************
 purge stale printers and reload from pre-populated pcap cache
**************************************************************************/
void reload_printers(struct tevent_context *ev,
		     struct messaging_context *msg_ctx)
{
	int n_services;
	int pnum;
	int snum;
	const char *pname;

	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 (!(lp_snum_ok(snum) && lp_print_ok(snum))) {
			continue;
		}

		pname = lp_printername(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));
			lp_killservice(snum);
		}
	}

	/* Make sure deleted printers are gone */
	load_printers(ev, msg_ctx);
}
Example #8
0
/*========================================================================
** The Main Procedure
** Initialization and FIFO command dispatch routine.
========================================================================*/
static int real_main(int argc, char *argv[])
	{
	const char function[] = "real_main";
	int option_foreground = FALSE;
	int FIFO;					/* First-in-first-out which feeds us requests */
	sigset_t lock_set;
	struct timeval next_tick;

	/* Initialize internation messages library. */
	#ifdef INTERNATIONAL
	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE_PPRD, LOCALEDIR);
	textdomain(PACKAGE_PPRD);
	#endif

	/*
	** Set some environment variables, (PATH, IFS, and
	** SHELL) for safety and for the convenience of the
	** programs we launch (HOME, and PPR_VERSION).
	** Remove unnecessary and potentially misleading
	** variables.
	*/
	set_ppr_env();
	prune_env();

	parse_command_line(argc, argv, &option_foreground);

	/* Switch all UIDs to USER_PPR, all GIDS to GROUP_PPR. */
	adjust_ids();

	/* If the --forground switch wasn't used, then dropt into background. */
	if(! option_foreground)
		gu_daemon(PPR_PPRD_UMASK);
	else
		umask(PPR_PPRD_UMASK);

	/* Change the home directory to the PPR home directory: */
	chdir(HOMEDIR);

	/* Create /var/spool/ppr/pprd.pid. */
	create_lock_file();

	/* Signal handlers for silly stuff. */
	signal_restarting(SIGPIPE, signal_ignore);
	signal_restarting(SIGHUP, signal_ignore);

	/* Signal handler for shutdown request. */
	signal_interupting(SIGTERM, sigterm_handler);

	/* Arrange for child termination to be noted. */
	signal_restarting(SIGCHLD, sigchld_handler);

	/* Move /var/spool/ppr/logs/pprd to pprd.old before we call debug()
	   for the first time (below). */
	rename_old_log_file();

	/*
	** This code must come after adjust_ids() and gu_daemon().
	** It makes the first log entry and tells queue-display
	** programs that we are starting up.
	*/
	debug("PPRD startup, pid=%ld", (long)getpid());
	state_update("STARTUP");

	/* Make sure the local node gets the node id of 0. */
	if(! nodeid_is_local_node(nodeid_assign(ppr_get_nodename())))
		fatal(1, "%s(): line %d: assertion failed", function, __LINE__);

	/* Initialize other subsystems. */
	question_init();

	/* Load the printers database. */
	DODEBUG_STARTUP(("loading printers database"));
	load_printers();

	/* Load the groups database. */
	DODEBUG_STARTUP(("loading groups database"));
	load_groups();

	/* Set up the FIFO. */
	DODEBUG_STARTUP(("opening FIFO"));
	FIFO = open_fifo();

	/* Initialize the queue.  This is likely to start printers. */
	DODEBUG_STARTUP(("initializing the queue"));
	initialize_queue();

	/* Schedule the first timer tick. */
	gettimeofday(&next_tick, NULL);
	next_tick.tv_sec += TICK_INTERVAL;

	/*
	** Create a signal block set which will be used to block SIGCHLD except
	** when we are calling select().
	*/
	sigemptyset(&lock_set);
	sigaddset(&lock_set, SIGCHLD);
	sigprocmask(SIG_BLOCK, &lock_set, (sigset_t*)NULL);

	/*
	** This is the Main Loop.  It runs until the sigterm_handler
	** sets sigterm_received.
	*/
	while(!sigterm_received)
		{
		int readyfds;					/* return value from select() */
		fd_set rfds;					/* list of file descriptors for select() to watch */
		struct timeval time_now;		/* the current time */

		DODEBUG_MAINLOOP(("top of main loop"));

		gettimeofday(&time_now, NULL);

		/* If it is time for or past time for the next tick, */
		if(gu_timeval_cmp(&time_now, &next_tick) >= 0)
			{
			readyfds = 0;
			}

		/* If it is not time for the next tick yet, */
		else
			{
			/* Set the select() timeout so that it will return in time for the
			   next tick(). */
			gu_timeval_cpy(&select_tv, &next_tick);
			gu_timeval_sub(&select_tv, &time_now);

			/* Create a file descriptor list which contains only the descriptor
			   of the FIFO. */
			FD_ZERO(&rfds);
			FD_SET(FIFO, &rfds);

			/* Call select() with SIGCHLD unblocked. */
			sigprocmask(SIG_UNBLOCK, &lock_set, (sigset_t*)NULL);
			readyfds = select(FIFO + 1, &rfds, NULL, NULL, &select_tv);
			sigprocmask(SIG_BLOCK, &lock_set, (sigset_t*)NULL);
			}

		/* If there is something to read, */
		if(readyfds > 0)
			{
			if(!FD_ISSET(FIFO, &rfds))
				fatal(0, "%s(): assertion failed: select() returned but FIFO not ready", function);
			do_command(FIFO);
			continue;
			}

		/* If the SIGCHLD handler set the flag, handle child termination.  Once
		   we have done that, we must go back to the top of the loop because
		   we don't really know if it is time for a tick() call yet. */
		if(sigchld_caught)
			{
			sigchld_caught = FALSE;
			reapchild();
			continue;
			}

		/* If there was no error and no file descriptors are ready, then the 
		   timeout must have expired.  Call tick(). */
		if(readyfds == 0)
			{
			tick();
			next_tick.tv_sec += TICK_INTERVAL;
			continue;
			}

		/* If interupted by a system call, restart it. */
		if(errno == EINTR)
			continue;

		/* If we get this far, there was an error. */
		fatal(0, "%s(): select() failed, errno=%d (%s)", function, errno, gu_strerror(errno));
		} /* end of endless while() loop */

	state_update("SHUTDOWN");
	fatal(0, "Received SIGTERM, exiting");
	} /* end of real_main() */
Example #9
0
/**
 * @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);
}
Example #10
0
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;
}