1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
/*
Unix SMB/Netbios implementation.
SPOOLSS Daemon
Copyright (C) Simo Sorce 2010
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
#include "librpc/gen_ndr/messaging.h"
#include "include/printing.h"
#include "rpc_server/rpc_server.h"
#define SPOOLSS_PIPE_NAME "spoolss"
static void spoolss_reopen_logs(void)
{
char *lfile = NULL;
int ret;
ret = asprintf(&lfile, "%s.spoolssd", lp_logfile());
if (ret > 0) {
lp_set_logfile(lfile);
SAFE_FREE(lfile);
}
reopen_logs();
}
static void smb_conf_updated(struct messaging_context *msg,
void *private_data,
uint32_t msg_type,
struct server_id server_id,
DATA_BLOB *data)
{
DEBUG(10, ("Got message saying smb.conf was updated. Reloading.\n"));
change_to_root_user();
reload_printers(msg);
spoolss_reopen_logs();
}
void start_spoolssd(void)
{
pid_t pid;
NTSTATUS status;
int ret;
DEBUG(1, ("Forking SPOOLSS Daemon\n"));
pid = sys_fork();
if (pid == -1) {
DEBUG(0, ("Failed to fork SPOOLSS [%s], aborting ...\n",
strerror(errno)));
exit(1);
}
if (pid) {
/* parent */
return;
}
/* child */
close_low_fds(false);
status = reinit_after_fork(server_messaging_context(),
server_event_context(),
procid_self(), true);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(0,("reinit_after_fork() failed\n"));
smb_panic("reinit_after_fork() failed");
}
spoolss_reopen_logs();
smbd_setup_sig_term_handler();
smbd_setup_sig_hup_handler();
if (!serverid_register(procid_self(),
FLAG_MSG_GENERAL|FLAG_MSG_SMBD
|FLAG_MSG_PRINT_GENERAL)) {
exit(1);
}
if (!locking_init()) {
exit(1);
}
messaging_register(server_messaging_context(), NULL,
MSG_PRINTER_UPDATE, print_queue_receive);
messaging_register(server_messaging_context(), NULL,
MSG_SMB_CONF_UPDATED, smb_conf_updated);
if (!setup_named_pipe_socket(SPOOLSS_PIPE_NAME, server_event_context())) {
exit(1);
}
/* loop forever */
ret = tevent_loop_wait(server_event_context());
/* should not be reached */
DEBUG(0,("background_queue: tevent_loop_wait() exited with %d - %s\n",
ret, (ret == 0) ? "out of events" : strerror(errno)));
exit(1);
}
|