s3:smb2_sesssetup: cancel and wait for pending requests on logoff
[Samba.git] / source3 / printing / spoolssd.c
blob7525fd1c2b63551d24824f609fc2fa2bc5531662
1 /*
2 Unix SMB/Netbios implementation.
3 SPOOLSS Daemon
4 Copyright (C) Simo Sorce <idra@samba.org> 2010-2011
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "includes.h"
20 #include "serverid.h"
21 #include "smbd/smbd.h"
23 #include "lib/util/util_process.h"
25 #include "messages.h"
26 #include "include/printing.h"
27 #include "printing/nt_printing_migrate_internal.h"
28 #include "printing/queue_process.h"
29 #include "printing/pcap.h"
30 #include "printing/load.h"
31 #include "ntdomain.h"
32 #include "librpc/gen_ndr/srv_winreg.h"
33 #include "librpc/gen_ndr/srv_spoolss.h"
34 #include "rpc_server/rpc_server.h"
35 #include "rpc_server/rpc_ep_register.h"
36 #include "rpc_server/rpc_config.h"
37 #include "rpc_server/spoolss/srv_spoolss_nt.h"
38 #include "librpc/rpc/dcerpc_ep.h"
39 #include "lib/server_prefork.h"
40 #include "lib/server_prefork_util.h"
42 #define SPOOLSS_PIPE_NAME "spoolss"
43 #define DAEMON_NAME "spoolssd"
45 static struct server_id parent_id;
46 static struct prefork_pool *spoolss_pool = NULL;
47 static int spoolss_child_id = 0;
49 static struct pf_daemon_config default_pf_spoolss_cfg = {
50 .prefork_status = PFH_INIT,
51 .min_children = 5,
52 .max_children = 25,
53 .spawn_rate = 5,
54 .max_allowed_clients = 100,
55 .child_min_life = 60 /* 1 minute minimum life time */
57 static struct pf_daemon_config pf_spoolss_cfg = { 0 };
59 pid_t start_spoolssd(struct tevent_context *ev_ctx,
60 struct messaging_context *msg_ctx);
62 static void spoolss_reopen_logs(int child_id)
64 char *lfile = lp_logfile(talloc_tos());
65 char *ext;
66 int rc;
68 if (child_id) {
69 rc = asprintf(&ext, "%s.%d", DAEMON_NAME, child_id);
70 } else {
71 rc = asprintf(&ext, "%s", DAEMON_NAME);
74 if (rc == -1) {
75 return;
78 rc = 0;
79 if (lfile == NULL || lfile[0] == '\0') {
80 rc = asprintf(&lfile, "%s/log.%s",
81 get_dyn_LOGFILEBASE(), ext);
82 } else {
83 if (strstr(lfile, ext) == NULL) {
84 if (child_id) {
85 rc = asprintf(&lfile, "%s.%d",
86 lp_logfile(talloc_tos()),
87 child_id);
88 } else {
89 rc = asprintf(&lfile, "%s.%s",
90 lp_logfile(talloc_tos()),
91 ext);
96 if (rc > 0) {
97 lp_set_logfile(lfile);
98 SAFE_FREE(lfile);
101 SAFE_FREE(ext);
103 reopen_logs();
106 static void update_conf(struct tevent_context *ev,
107 struct messaging_context *msg)
109 change_to_root_user();
110 lp_load(get_dyn_CONFIGFILE(), true, false, false, true);
111 load_printers(ev, msg);
113 spoolss_reopen_logs(spoolss_child_id);
114 if (spoolss_child_id == 0) {
115 pfh_daemon_config(DAEMON_NAME,
116 &pf_spoolss_cfg,
117 &default_pf_spoolss_cfg);
118 pfh_manage_pool(ev, msg, &pf_spoolss_cfg, spoolss_pool);
122 static void smb_conf_updated(struct messaging_context *msg,
123 void *private_data,
124 uint32_t msg_type,
125 struct server_id server_id,
126 DATA_BLOB *data)
128 struct tevent_context *ev_ctx = talloc_get_type_abort(private_data,
129 struct tevent_context);
131 DEBUG(10, ("Got message saying smb.conf was updated. Reloading.\n"));
132 update_conf(ev_ctx, msg);
135 static void update_pcap(struct tevent_context *ev_ctx,
136 struct messaging_context *msg_ctx)
138 change_to_root_user();
139 delete_and_reload_printers(ev_ctx, msg_ctx);
142 static void pcap_updated(struct messaging_context *msg,
143 void *private_data,
144 uint32_t msg_type,
145 struct server_id server_id,
146 DATA_BLOB *data)
148 struct tevent_context *ev_ctx;
150 ev_ctx = talloc_get_type_abort(private_data, struct tevent_context);
152 DEBUG(10, ("Got message that pcap updated. Reloading.\n"));
153 update_pcap(ev_ctx, msg);
156 static void spoolss_sig_term_handler(struct tevent_context *ev,
157 struct tevent_signal *se,
158 int signum,
159 int count,
160 void *siginfo,
161 void *private_data)
163 exit_server_cleanly("termination signal");
166 static void spoolss_setup_sig_term_handler(struct tevent_context *ev_ctx)
168 struct tevent_signal *se;
170 se = tevent_add_signal(ev_ctx,
171 ev_ctx,
172 SIGTERM, 0,
173 spoolss_sig_term_handler,
174 NULL);
175 if (!se) {
176 exit_server("failed to setup SIGTERM handler");
180 static void spoolss_sig_hup_handler(struct tevent_context *ev,
181 struct tevent_signal *se,
182 int signum,
183 int count,
184 void *siginfo,
185 void *pvt)
187 struct messaging_context *msg_ctx;
189 msg_ctx = talloc_get_type_abort(pvt, struct messaging_context);
191 DEBUG(1,("Reloading printers after SIGHUP\n"));
192 update_conf(ev, msg_ctx);
194 /* relay to all children */
195 if (spoolss_pool) {
196 prefork_send_signal_to_all(spoolss_pool, SIGHUP);
200 static void spoolss_setup_sig_hup_handler(struct tevent_context *ev_ctx,
201 struct messaging_context *msg_ctx)
203 struct tevent_signal *se;
205 se = tevent_add_signal(ev_ctx,
206 ev_ctx,
207 SIGHUP, 0,
208 spoolss_sig_hup_handler,
209 msg_ctx);
210 if (!se) {
211 exit_server("failed to setup SIGHUP handler");
215 static bool spoolss_init_cb(void *ptr)
217 struct messaging_context *msg_ctx = talloc_get_type_abort(
218 ptr, struct messaging_context);
220 return nt_printing_tdb_migrate(msg_ctx);
223 static bool spoolss_shutdown_cb(void *ptr)
225 srv_spoolss_cleanup();
227 return true;
230 /* Children */
232 static void spoolss_chld_sig_hup_handler(struct tevent_context *ev,
233 struct tevent_signal *se,
234 int signum,
235 int count,
236 void *siginfo,
237 void *pvt)
239 struct messaging_context *msg_ctx;
241 msg_ctx = talloc_get_type_abort(pvt, struct messaging_context);
243 change_to_root_user();
244 DEBUG(1,("Reloading printers after SIGHUP\n"));
245 load_printers(ev, msg_ctx);
246 spoolss_reopen_logs(spoolss_child_id);
249 static bool spoolss_setup_chld_hup_handler(struct tevent_context *ev_ctx,
250 struct messaging_context *msg_ctx,
251 struct pf_worker_data *pf)
253 struct tevent_signal *se;
255 se = tevent_add_signal(ev_ctx,
256 ev_ctx,
257 SIGHUP, 0,
258 spoolss_chld_sig_hup_handler,
259 msg_ctx);
260 if (!se) {
261 DEBUG(1, ("failed to setup SIGHUP handler"));
262 return false;
265 return true;
268 static void parent_ping(struct messaging_context *msg_ctx,
269 void *private_data,
270 uint32_t msg_type,
271 struct server_id server_id,
272 DATA_BLOB *data)
275 /* The fact we received this message is enough to let make the event
276 * loop if it was idle. spoolss_children_main will cycle through
277 * spoolss_next_client at least once. That function will take whatever
278 * action is necessary */
280 DEBUG(10, ("Got message that the parent changed status.\n"));
281 return;
284 static bool spoolss_child_init(struct tevent_context *ev_ctx,
285 int child_id, struct pf_worker_data *pf)
287 NTSTATUS status;
288 struct rpc_srv_callbacks spoolss_cb;
289 struct messaging_context *msg_ctx = messaging_init(NULL, ev_ctx);
290 bool ok;
292 status = reinit_after_fork(msg_ctx, ev_ctx,
293 true);
294 if (!NT_STATUS_IS_OK(status)) {
295 DEBUG(0,("reinit_after_fork() failed\n"));
296 smb_panic("reinit_after_fork() failed");
299 prctl_set_comment("spoolssd-child");
301 spoolss_child_id = child_id;
302 spoolss_reopen_logs(child_id);
304 ok = spoolss_setup_chld_hup_handler(ev_ctx, msg_ctx, pf);
305 if (!ok) {
306 return false;
309 if (!serverid_register(messaging_server_id(msg_ctx),
310 FLAG_MSG_GENERAL |
311 FLAG_MSG_PRINT_GENERAL)) {
312 return false;
315 if (!locking_init()) {
316 return false;
319 messaging_register(msg_ctx, ev_ctx,
320 MSG_SMB_CONF_UPDATED, smb_conf_updated);
321 messaging_register(msg_ctx, ev_ctx, MSG_PRINTER_PCAP,
322 pcap_updated);
323 messaging_register(msg_ctx, ev_ctx,
324 MSG_PREFORK_PARENT_EVENT, parent_ping);
326 /* As soon as messaging is up check if pcap has been loaded already.
327 * If so then we probably missed a message and should load_printers()
328 * ourselves. If pcap has not been loaded yet, then ignore, we will get
329 * a message as soon as the bq process completes the reload. */
330 if (pcap_cache_loaded()) {
331 load_printers(ev_ctx, msg_ctx);
334 /* try to reinit rpc queues */
335 spoolss_cb.init = spoolss_init_cb;
336 spoolss_cb.shutdown = spoolss_shutdown_cb;
337 spoolss_cb.private_data = msg_ctx;
339 status = rpc_winreg_init(NULL);
340 if (!NT_STATUS_IS_OK(status)) {
341 DEBUG(0, ("Failed to register winreg rpc inteface! (%s)\n",
342 nt_errstr(status)));
343 return false;
346 status = rpc_spoolss_init(&spoolss_cb);
347 if (!NT_STATUS_IS_OK(status)) {
348 DEBUG(0, ("Failed to register spoolss rpc inteface! (%s)\n",
349 nt_errstr(status)));
350 return false;
353 return true;
356 struct spoolss_children_data {
357 struct tevent_context *ev_ctx;
358 struct messaging_context *msg_ctx;
359 struct pf_worker_data *pf;
360 int listen_fd_size;
361 int *listen_fds;
364 static void spoolss_next_client(void *pvt);
366 static int spoolss_children_main(struct tevent_context *ev_ctx,
367 struct messaging_context *msg_ctx,
368 struct pf_worker_data *pf,
369 int child_id,
370 int listen_fd_size,
371 int *listen_fds,
372 void *private_data)
374 struct spoolss_children_data *data;
375 bool ok;
376 int ret;
378 ok = spoolss_child_init(ev_ctx, child_id, pf);
379 if (!ok) {
380 return 1;
383 data = talloc(ev_ctx, struct spoolss_children_data);
384 if (!data) {
385 return 1;
387 data->pf = pf;
388 data->ev_ctx = ev_ctx;
389 data->msg_ctx = msg_ctx;
390 data->listen_fd_size = listen_fd_size;
391 data->listen_fds = listen_fds;
393 /* loop until it is time to exit */
394 while (pf->status != PF_WORKER_EXITING) {
395 /* try to see if it is time to schedule the next client */
396 spoolss_next_client(data);
398 ret = tevent_loop_once(ev_ctx);
399 if (ret != 0) {
400 DEBUG(0, ("tevent_loop_once() exited with %d: %s\n",
401 ret, strerror(errno)));
402 pf->status = PF_WORKER_EXITING;
406 return ret;
409 static void spoolss_client_terminated(void *pvt)
411 struct spoolss_children_data *data;
413 data = talloc_get_type_abort(pvt, struct spoolss_children_data);
415 pfh_client_terminated(data->pf);
417 spoolss_next_client(pvt);
420 struct spoolss_new_client {
421 struct spoolss_children_data *data;
422 struct tsocket_address *srv_addr;
423 struct tsocket_address *cli_addr;
426 static void spoolss_handle_client(struct tevent_req *req);
428 static void spoolss_next_client(void *pvt)
430 struct tevent_req *req;
431 struct spoolss_children_data *data;
432 struct spoolss_new_client *next;
434 data = talloc_get_type_abort(pvt, struct spoolss_children_data);
436 if (!pfh_child_allowed_to_accept(data->pf)) {
437 /* nothing to do for now we are already listening
438 * or we are not allowed to listen further */
439 return;
442 next = talloc_zero(data, struct spoolss_new_client);
443 if (!next) {
444 DEBUG(1, ("Out of memory!?\n"));
445 return;
447 next->data = data;
449 req = prefork_listen_send(next, data->ev_ctx, data->pf,
450 data->listen_fd_size,
451 data->listen_fds);
452 if (!req) {
453 DEBUG(1, ("Failed to make listening request!?\n"));
454 talloc_free(next);
455 return;
457 tevent_req_set_callback(req, spoolss_handle_client, next);
460 static void spoolss_handle_client(struct tevent_req *req)
462 struct spoolss_children_data *data;
463 struct spoolss_new_client *client;
464 const DATA_BLOB ping = data_blob_null;
465 int ret;
466 int sd;
468 client = tevent_req_callback_data(req, struct spoolss_new_client);
469 data = client->data;
471 ret = prefork_listen_recv(req, client, &sd,
472 &client->srv_addr, &client->cli_addr);
474 /* this will free the request too */
475 talloc_free(client);
477 if (ret != 0) {
478 DEBUG(6, ("No client connection was available after all!\n"));
479 return;
482 /* Warn parent that our status changed */
483 messaging_send(data->msg_ctx, parent_id,
484 MSG_PREFORK_CHILD_EVENT, &ping);
486 DEBUG(2, ("Spoolss preforked child %d got client connection!\n",
487 (int)(data->pf->pid)));
489 named_pipe_accept_function(data->ev_ctx, data->msg_ctx,
490 SPOOLSS_PIPE_NAME, sd,
491 spoolss_client_terminated, data);
494 /* ==== Main Process Functions ==== */
496 extern pid_t background_lpq_updater_pid;
497 static char *bq_logfile;
499 static void check_updater_child(struct tevent_context *ev_ctx,
500 struct messaging_context *msg_ctx)
502 int status;
503 pid_t pid;
505 if (background_lpq_updater_pid == -1) {
506 return;
509 pid = sys_waitpid(background_lpq_updater_pid, &status, WNOHANG);
510 if (pid > 0) {
511 DEBUG(2, ("The background queue child died... Restarting!\n"));
512 pid = start_background_queue(ev_ctx, msg_ctx, bq_logfile);
513 background_lpq_updater_pid = pid;
517 static void child_ping(struct messaging_context *msg_ctx,
518 void *private_data,
519 uint32_t msg_type,
520 struct server_id server_id,
521 DATA_BLOB *data)
523 struct tevent_context *ev_ctx;
525 ev_ctx = talloc_get_type_abort(private_data, struct tevent_context);
527 DEBUG(10, ("Got message that a child changed status.\n"));
528 pfh_manage_pool(ev_ctx, msg_ctx, &pf_spoolss_cfg, spoolss_pool);
531 static bool spoolssd_schedule_check(struct tevent_context *ev_ctx,
532 struct messaging_context *msg_ctx,
533 struct timeval current_time);
534 static void spoolssd_check_children(struct tevent_context *ev_ctx,
535 struct tevent_timer *te,
536 struct timeval current_time,
537 void *pvt);
539 static void spoolssd_sigchld_handler(struct tevent_context *ev_ctx,
540 struct prefork_pool *pfp,
541 void *pvt)
543 struct messaging_context *msg_ctx;
545 msg_ctx = talloc_get_type_abort(pvt, struct messaging_context);
547 /* run pool management so we can fork/retire or increase
548 * the allowed connections per child based on load */
549 pfh_manage_pool(ev_ctx, msg_ctx, &pf_spoolss_cfg, spoolss_pool);
551 /* also check if the updater child is alive and well */
552 check_updater_child(ev_ctx, msg_ctx);
555 static bool spoolssd_setup_children_monitor(struct tevent_context *ev_ctx,
556 struct messaging_context *msg_ctx)
558 bool ok;
560 /* add our oun sigchld callback */
561 prefork_set_sigchld_callback(spoolss_pool,
562 spoolssd_sigchld_handler, msg_ctx);
564 ok = spoolssd_schedule_check(ev_ctx, msg_ctx,
565 tevent_timeval_current());
566 return ok;
569 static bool spoolssd_schedule_check(struct tevent_context *ev_ctx,
570 struct messaging_context *msg_ctx,
571 struct timeval current_time)
573 struct tevent_timer *te;
574 struct timeval next_event;
576 /* check situation again in 10 seconds */
577 next_event = tevent_timeval_current_ofs(10, 0);
579 /* TODO: check when the socket becomes readable, so that children
580 * are checked only when there is some activity ? */
581 te = tevent_add_timer(ev_ctx, spoolss_pool, next_event,
582 spoolssd_check_children, msg_ctx);
583 if (!te) {
584 DEBUG(2, ("Failed to set up children monitoring!\n"));
585 return false;
588 return true;
591 static void spoolssd_check_children(struct tevent_context *ev_ctx,
592 struct tevent_timer *te,
593 struct timeval current_time,
594 void *pvt)
596 struct messaging_context *msg_ctx;
598 msg_ctx = talloc_get_type_abort(pvt, struct messaging_context);
600 pfh_manage_pool(ev_ctx, msg_ctx, &pf_spoolss_cfg, spoolss_pool);
602 spoolssd_schedule_check(ev_ctx, msg_ctx, current_time);
605 static void print_queue_forward(struct messaging_context *msg,
606 void *private_data,
607 uint32_t msg_type,
608 struct server_id server_id,
609 DATA_BLOB *data)
611 messaging_send_buf(msg, pid_to_procid(background_lpq_updater_pid),
612 MSG_PRINTER_UPDATE, data->data, data->length);
615 static char *get_bq_logfile(void)
617 char *lfile = lp_logfile(talloc_tos());
618 int rc;
620 if (lfile == NULL || lfile[0] == '\0') {
621 rc = asprintf(&lfile, "%s/log.%s.bq",
622 get_dyn_LOGFILEBASE(), DAEMON_NAME);
623 } else {
624 rc = asprintf(&lfile, "%s.bq", lp_logfile(talloc_tos()));
626 if (rc == -1) {
627 lfile = NULL;
629 return lfile;
632 pid_t start_spoolssd(struct tevent_context *ev_ctx,
633 struct messaging_context *msg_ctx)
635 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
636 struct rpc_srv_callbacks spoolss_cb;
637 struct dcerpc_binding_vector *v;
638 TALLOC_CTX *mem_ctx;
639 pid_t pid;
640 NTSTATUS status;
641 int listen_fd;
642 int ret;
643 bool ok;
645 DEBUG(1, ("Forking SPOOLSS Daemon\n"));
648 * Block signals before forking child as it will have to
649 * set its own handlers. Child will re-enable SIGHUP as
650 * soon as the handlers are set up.
652 BlockSignals(true, SIGTERM);
653 BlockSignals(true, SIGHUP);
655 pid = fork();
657 if (pid == -1) {
658 DEBUG(0, ("Failed to fork SPOOLSS [%s]\n",
659 strerror(errno)));
662 /* parent or error */
663 if (pid != 0) {
665 /* Re-enable SIGHUP before returnig */
666 BlockSignals(false, SIGTERM);
667 BlockSignals(false, SIGHUP);
668 return pid;
671 status = reinit_after_fork(msg_ctx,
672 ev_ctx,
673 true);
674 if (!NT_STATUS_IS_OK(status)) {
675 DEBUG(0,("reinit_after_fork() failed\n"));
676 smb_panic("reinit_after_fork() failed");
679 prctl_set_comment("spoolssd-master");
681 /* save the parent process id so the children can use it later */
682 parent_id = messaging_server_id(msg_ctx);
684 spoolss_reopen_logs(0);
685 pfh_daemon_config(DAEMON_NAME,
686 &pf_spoolss_cfg,
687 &default_pf_spoolss_cfg);
689 spoolss_setup_sig_term_handler(ev_ctx);
690 spoolss_setup_sig_hup_handler(ev_ctx, msg_ctx);
692 BlockSignals(false, SIGTERM);
693 BlockSignals(false, SIGHUP);
695 /* always start the backgroundqueue listner in spoolssd */
696 bq_logfile = get_bq_logfile();
697 pid = start_background_queue(ev_ctx, msg_ctx, bq_logfile);
698 if (pid > 0) {
699 background_lpq_updater_pid = pid;
702 /* the listening fd must be created before the children are actually
703 * forked out. */
704 listen_fd = create_named_pipe_socket(SPOOLSS_PIPE_NAME);
705 if (listen_fd == -1) {
706 exit(1);
709 ret = listen(listen_fd, pf_spoolss_cfg.max_allowed_clients);
710 if (ret == -1) {
711 DEBUG(0, ("Failed to listen on spoolss pipe - %s\n",
712 strerror(errno)));
713 exit(1);
716 /* start children before any more initialization is done */
717 ok = prefork_create_pool(ev_ctx, /* mem_ctx */
718 ev_ctx, msg_ctx,
719 1, &listen_fd,
720 pf_spoolss_cfg.min_children,
721 pf_spoolss_cfg.max_children,
722 &spoolss_children_main, NULL,
723 &spoolss_pool);
724 if (!ok) {
725 exit(1);
728 if (!serverid_register(messaging_server_id(msg_ctx),
729 FLAG_MSG_GENERAL |
730 FLAG_MSG_PRINT_GENERAL)) {
731 exit(1);
734 if (!locking_init()) {
735 exit(1);
738 messaging_register(msg_ctx, ev_ctx,
739 MSG_SMB_CONF_UPDATED, smb_conf_updated);
740 messaging_register(msg_ctx, NULL, MSG_PRINTER_UPDATE,
741 print_queue_forward);
742 messaging_register(msg_ctx, ev_ctx, MSG_PRINTER_PCAP,
743 pcap_updated);
744 messaging_register(msg_ctx, ev_ctx,
745 MSG_PREFORK_CHILD_EVENT, child_ping);
747 /* As soon as messaging is up check if pcap has been loaded already.
748 * If so then we probably missed a message and should load_printers()
749 * ourselves. If pcap has not been loaded yet, then ignore, we will get
750 * a message as soon as the bq process completes the reload. */
751 if (pcap_cache_loaded()) {
752 load_printers(ev_ctx, msg_ctx);
755 mem_ctx = talloc_new(NULL);
756 if (mem_ctx == NULL) {
757 exit(1);
761 * Initialize spoolss with an init function to convert printers first.
762 * static_init_rpc will try to initialize the spoolss server too but you
763 * can't register it twice.
765 spoolss_cb.init = spoolss_init_cb;
766 spoolss_cb.shutdown = spoolss_shutdown_cb;
767 spoolss_cb.private_data = msg_ctx;
769 status = rpc_winreg_init(NULL);
770 if (!NT_STATUS_IS_OK(status)) {
771 DEBUG(0, ("Failed to register winreg rpc inteface! (%s)\n",
772 nt_errstr(status)));
773 exit(1);
776 status = rpc_spoolss_init(&spoolss_cb);
777 if (!NT_STATUS_IS_OK(status)) {
778 DEBUG(0, ("Failed to register spoolss rpc inteface! (%s)\n",
779 nt_errstr(status)));
780 exit(1);
783 if (epm_mode != RPC_SERVICE_MODE_DISABLED &&
784 (lp_parm_bool(-1, "rpc_server", "register_embedded_np", false))) {
785 status = dcerpc_binding_vector_new(mem_ctx, &v);
786 if (!NT_STATUS_IS_OK(status)) {
787 DEBUG(0, ("Failed to create binding vector (%s)\n",
788 nt_errstr(status)));
789 exit(1);
792 status = dcerpc_binding_vector_add_np_default(&ndr_table_spoolss, v);
793 if (!NT_STATUS_IS_OK(status)) {
794 DEBUG(0, ("Failed to add np to binding vector (%s)\n",
795 nt_errstr(status)));
796 exit(1);
799 status = rpc_ep_register(ev_ctx, msg_ctx, &ndr_table_spoolss, v);
800 if (!NT_STATUS_IS_OK(status)) {
801 DEBUG(0, ("Failed to register spoolss endpoint! (%s)\n",
802 nt_errstr(status)));
803 exit(1);
807 talloc_free(mem_ctx);
809 ok = spoolssd_setup_children_monitor(ev_ctx, msg_ctx);
810 if (!ok) {
811 DEBUG(0, ("Failed to setup children monitoring!\n"));
812 exit(1);
815 DEBUG(1, ("SPOOLSS Daemon Started (%u)\n", (unsigned int)getpid()));
817 pfh_manage_pool(ev_ctx, msg_ctx, &pf_spoolss_cfg, spoolss_pool);
819 /* loop forever */
820 ret = tevent_loop_wait(ev_ctx);
822 /* should not be reached */
823 DEBUG(0,("spoolssd tevent_loop_wait() exited with %d - %s\n",
824 ret, (ret == 0) ? "out of events" : strerror(errno)));
825 exit(1);