author | jose borrego <Jose.Borrego@Sun.COM> |
Mon, 13 Oct 2008 22:40:15 -0600 | |
changeset 7826 | 31ae58c8daeb |
parent 7348 | 73b61202d5d6 |
child 7961 | 4b5e3051f38b |
permissions | -rw-r--r-- |
5331 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
4 |
* The contents of this file are subject to the terms of the |
|
5 |
* Common Development and Distribution License (the "License"). |
|
6 |
* You may not use this file except in compliance with the License. |
|
7 |
* |
|
8 |
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 |
* or http://www.opensolaris.org/os/licensing. |
|
10 |
* See the License for the specific language governing permissions |
|
11 |
* and limitations under the License. |
|
12 |
* |
|
13 |
* When distributing Covered Code, include this CDDL HEADER in each |
|
14 |
* file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 |
* If applicable, add the following below this CDDL HEADER, with the |
|
16 |
* fields enclosed by brackets "[]" replaced with your own identifying |
|
17 |
* information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 |
* |
|
19 |
* CDDL HEADER END |
|
20 |
*/ |
|
21 |
/* |
|
5772
237ac22142fe
6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents:
5521
diff
changeset
|
22 |
* Copyright 2008 Sun Microsystems, Inc. All rights reserved. |
5331 | 23 |
* Use is subject to license terms. |
24 |
*/ |
|
25 |
||
7348
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
26 |
#pragma ident "@(#)smbd_main.c 1.13 08/08/05 SMI" |
5331 | 27 |
|
28 |
#include <sys/types.h> |
|
29 |
#include <sys/stat.h> |
|
30 |
#include <sys/ioccom.h> |
|
31 |
#include <stdio.h> |
|
32 |
#include <string.h> |
|
33 |
#include <strings.h> |
|
34 |
#include <stdlib.h> |
|
35 |
#include <unistd.h> |
|
36 |
#include <stdarg.h> |
|
37 |
#include <fcntl.h> |
|
38 |
#include <wait.h> |
|
39 |
#include <signal.h> |
|
40 |
#include <libscf.h> |
|
41 |
#include <limits.h> |
|
42 |
#include <priv_utils.h> |
|
43 |
#include <door.h> |
|
44 |
#include <errno.h> |
|
45 |
#include <syslog.h> |
|
46 |
#include <pthread.h> |
|
47 |
#include <time.h> |
|
48 |
#include <libscf.h> |
|
49 |
#include <zone.h> |
|
7348
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
50 |
#include <time.h> |
5331 | 51 |
#include <tzfile.h> |
52 |
#include <libgen.h> |
|
53 |
#include <pwd.h> |
|
54 |
#include <grp.h> |
|
55 |
||
56 |
#include <smbsrv/smb_door_svc.h> |
|
57 |
#include <smbsrv/smb_ioctl.h> |
|
58 |
#include <smbsrv/libsmb.h> |
|
59 |
#include <smbsrv/libsmbns.h> |
|
60 |
#include <smbsrv/libsmbrdr.h> |
|
61 |
#include <smbsrv/libmlsvc.h> |
|
62 |
||
63 |
#include "smbd.h" |
|
64 |
||
65 |
#define DRV_DEVICE_PATH "/devices/pseudo/smbsrv@0:smbsrv" |
|
66 |
#define SMB_DBDIR "/var/smb" |
|
67 |
||
6139
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
68 |
extern void *smbd_nbt_listener(void *); |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
69 |
extern void *smbd_tcp_listener(void *); |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
70 |
|
5331 | 71 |
static int smbd_daemonize_init(void); |
72 |
static void smbd_daemonize_fini(int, int); |
|
73 |
||
6432
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
74 |
static int smbd_kernel_bind(void); |
5331 | 75 |
static void smbd_kernel_unbind(void); |
76 |
static int smbd_already_running(void); |
|
77 |
||
78 |
static int smbd_service_init(void); |
|
79 |
static void smbd_service_fini(void); |
|
80 |
||
81 |
static int smbd_setup_options(int argc, char *argv[]); |
|
82 |
static void smbd_usage(FILE *fp); |
|
83 |
static void smbd_report(const char *fmt, ...); |
|
84 |
||
85 |
static void smbd_sig_handler(int sig); |
|
86 |
||
7348
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
87 |
static int32_t smbd_gmtoff(void); |
5331 | 88 |
static int smbd_localtime_init(void); |
89 |
static void *smbd_localtime_monitor(void *arg); |
|
90 |
||
91 |
static pthread_t localtime_thr; |
|
92 |
||
93 |
static int smbd_refresh_init(void); |
|
94 |
static void smbd_refresh_fini(void); |
|
95 |
static void *smbd_refresh_monitor(void *); |
|
6139
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
96 |
static pthread_t nbt_listener; |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
97 |
static pthread_t tcp_listener; |
5331 | 98 |
static pthread_t refresh_thr; |
99 |
static pthread_cond_t refresh_cond; |
|
100 |
static pthread_mutex_t refresh_mutex; |
|
101 |
||
6139
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
102 |
smbd_t smbd; |
5331 | 103 |
|
104 |
/* |
|
105 |
* smbd user land daemon |
|
106 |
* |
|
107 |
* Use SMF error codes only on return or exit. |
|
108 |
*/ |
|
109 |
int |
|
110 |
main(int argc, char *argv[]) |
|
111 |
{ |
|
6432
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
112 |
struct sigaction act; |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
113 |
sigset_t set; |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
114 |
uid_t uid; |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
115 |
int pfd = -1; |
7052 | 116 |
int sigval; |
5331 | 117 |
|
118 |
smbd.s_pname = basename(argv[0]); |
|
119 |
openlog(smbd.s_pname, LOG_PID | LOG_NOWAIT, LOG_DAEMON); |
|
120 |
||
121 |
if (smbd_setup_options(argc, argv) != 0) |
|
122 |
return (SMF_EXIT_ERR_FATAL); |
|
123 |
||
124 |
if ((uid = getuid()) != smbd.s_uid) { |
|
125 |
smbd_report("user %d: %s", uid, strerror(EPERM)); |
|
126 |
return (SMF_EXIT_ERR_FATAL); |
|
127 |
} |
|
128 |
||
129 |
if (getzoneid() != GLOBAL_ZONEID) { |
|
130 |
smbd_report("non-global zones are not supported"); |
|
131 |
return (SMF_EXIT_ERR_FATAL); |
|
132 |
} |
|
133 |
||
134 |
if (is_system_labeled()) { |
|
135 |
smbd_report("Trusted Extensions not supported"); |
|
136 |
return (SMF_EXIT_ERR_FATAL); |
|
137 |
} |
|
138 |
||
139 |
if (smbd_already_running()) |
|
140 |
return (SMF_EXIT_OK); |
|
141 |
||
142 |
(void) sigfillset(&set); |
|
143 |
(void) sigdelset(&set, SIGABRT); |
|
144 |
||
145 |
(void) sigfillset(&act.sa_mask); |
|
146 |
act.sa_handler = smbd_sig_handler; |
|
147 |
act.sa_flags = 0; |
|
148 |
||
149 |
(void) sigaction(SIGTERM, &act, NULL); |
|
150 |
(void) sigaction(SIGHUP, &act, NULL); |
|
151 |
(void) sigaction(SIGINT, &act, NULL); |
|
152 |
(void) sigaction(SIGPIPE, &act, NULL); |
|
153 |
||
154 |
(void) sigdelset(&set, SIGTERM); |
|
155 |
(void) sigdelset(&set, SIGHUP); |
|
156 |
(void) sigdelset(&set, SIGINT); |
|
157 |
(void) sigdelset(&set, SIGPIPE); |
|
158 |
||
159 |
if (smbd.s_fg) { |
|
160 |
(void) sigdelset(&set, SIGTSTP); |
|
161 |
(void) sigdelset(&set, SIGTTIN); |
|
162 |
(void) sigdelset(&set, SIGTTOU); |
|
163 |
||
164 |
if (smbd_service_init() != 0) { |
|
165 |
smbd_report("service initialization failed"); |
|
166 |
exit(SMF_EXIT_ERR_FATAL); |
|
167 |
} |
|
168 |
} else { |
|
169 |
/* |
|
170 |
* "pfd" is a pipe descriptor -- any fatal errors |
|
171 |
* during subsequent initialization of the child |
|
172 |
* process should be written to this pipe and the |
|
173 |
* parent will report this error as the exit status. |
|
174 |
*/ |
|
175 |
pfd = smbd_daemonize_init(); |
|
176 |
||
177 |
if (smbd_service_init() != 0) { |
|
178 |
smbd_report("daemon initialization failed"); |
|
179 |
exit(SMF_EXIT_ERR_FATAL); |
|
180 |
} |
|
181 |
||
182 |
smbd_daemonize_fini(pfd, SMF_EXIT_OK); |
|
183 |
} |
|
184 |
||
185 |
(void) atexit(smbd_service_fini); |
|
186 |
||
187 |
while (!smbd.s_shutdown_flag) { |
|
7052 | 188 |
if (smbd.s_sigval == 0) |
189 |
(void) sigsuspend(&set); |
|
5331 | 190 |
|
7052 | 191 |
sigval = smbd.s_sigval; |
192 |
smbd.s_sigval = 0; |
|
193 |
||
194 |
switch (sigval) { |
|
5331 | 195 |
case 0: |
196 |
case SIGPIPE: |
|
197 |
break; |
|
198 |
||
199 |
case SIGHUP: |
|
200 |
/* Refresh config was triggered */ |
|
201 |
if (smbd.s_fg) |
|
202 |
smbd_report("reconfiguration requested"); |
|
203 |
(void) pthread_cond_signal(&refresh_cond); |
|
204 |
break; |
|
205 |
||
206 |
default: |
|
207 |
/* |
|
208 |
* Typically SIGINT or SIGTERM. |
|
209 |
*/ |
|
210 |
smbd.s_shutdown_flag = 1; |
|
211 |
break; |
|
212 |
} |
|
213 |
} |
|
214 |
||
215 |
smbd_service_fini(); |
|
216 |
closelog(); |
|
217 |
return (SMF_EXIT_OK); |
|
218 |
} |
|
219 |
||
220 |
/* |
|
221 |
* This function will fork off a child process, |
|
222 |
* from which only the child will return. |
|
223 |
* |
|
224 |
* Use SMF error codes only on exit. |
|
225 |
*/ |
|
226 |
static int |
|
227 |
smbd_daemonize_init(void) |
|
228 |
{ |
|
229 |
int status, pfds[2]; |
|
230 |
sigset_t set, oset; |
|
231 |
pid_t pid; |
|
232 |
int rc; |
|
233 |
||
234 |
/* |
|
235 |
* Reset privileges to the minimum set required. We continue |
|
236 |
* to run as root to create and access files in /var. |
|
237 |
*/ |
|
238 |
rc = __init_daemon_priv(PU_RESETGROUPS | PU_LIMITPRIVS, |
|
239 |
smbd.s_uid, smbd.s_gid, |
|
240 |
PRIV_NET_MAC_AWARE, PRIV_NET_PRIVADDR, PRIV_PROC_AUDIT, |
|
241 |
PRIV_SYS_DEVICES, PRIV_SYS_SMB, NULL); |
|
242 |
||
243 |
if (rc != 0) { |
|
244 |
smbd_report("insufficient privileges"); |
|
245 |
exit(SMF_EXIT_ERR_FATAL); |
|
246 |
} |
|
247 |
||
248 |
/* |
|
249 |
* Block all signals prior to the fork and leave them blocked in the |
|
250 |
* parent so we don't get in a situation where the parent gets SIGINT |
|
251 |
* and returns non-zero exit status and the child is actually running. |
|
252 |
* In the child, restore the signal mask once we've done our setsid(). |
|
253 |
*/ |
|
254 |
(void) sigfillset(&set); |
|
255 |
(void) sigdelset(&set, SIGABRT); |
|
256 |
(void) sigprocmask(SIG_BLOCK, &set, &oset); |
|
257 |
||
258 |
if (pipe(pfds) == -1) { |
|
259 |
smbd_report("unable to create pipe"); |
|
260 |
exit(SMF_EXIT_ERR_FATAL); |
|
261 |
} |
|
262 |
||
263 |
closelog(); |
|
264 |
||
265 |
if ((pid = fork()) == -1) { |
|
266 |
openlog(smbd.s_pname, LOG_PID | LOG_NOWAIT, LOG_DAEMON); |
|
267 |
smbd_report("unable to fork"); |
|
268 |
closelog(); |
|
269 |
exit(SMF_EXIT_ERR_FATAL); |
|
270 |
} |
|
271 |
||
272 |
/* |
|
273 |
* If we're the parent process, wait for either the child to send us |
|
274 |
* the appropriate exit status over the pipe or for the read to fail |
|
275 |
* (presumably with 0 for EOF if our child terminated abnormally). |
|
276 |
* If the read fails, exit with either the child's exit status if it |
|
277 |
* exited or with SMF_EXIT_ERR_FATAL if it died from a fatal signal. |
|
278 |
*/ |
|
279 |
if (pid != 0) { |
|
280 |
(void) close(pfds[1]); |
|
281 |
||
282 |
if (read(pfds[0], &status, sizeof (status)) == sizeof (status)) |
|
283 |
_exit(status); |
|
284 |
||
285 |
if (waitpid(pid, &status, 0) == pid && WIFEXITED(status)) |
|
286 |
_exit(WEXITSTATUS(status)); |
|
287 |
||
288 |
_exit(SMF_EXIT_ERR_FATAL); |
|
289 |
} |
|
290 |
||
291 |
openlog(smbd.s_pname, LOG_PID | LOG_NOWAIT, LOG_DAEMON); |
|
292 |
smbd.s_pid = getpid(); |
|
293 |
(void) setsid(); |
|
294 |
(void) sigprocmask(SIG_SETMASK, &oset, NULL); |
|
295 |
(void) chdir("/"); |
|
296 |
(void) umask(022); |
|
297 |
(void) close(pfds[0]); |
|
298 |
||
299 |
return (pfds[1]); |
|
300 |
} |
|
301 |
||
302 |
static void |
|
303 |
smbd_daemonize_fini(int fd, int exit_status) |
|
304 |
{ |
|
305 |
/* |
|
306 |
* Now that we're running, if a pipe fd was specified, write an exit |
|
307 |
* status to it to indicate that our parent process can safely detach. |
|
308 |
* Then proceed to loading the remaining non-built-in modules. |
|
309 |
*/ |
|
310 |
if (fd >= 0) |
|
311 |
(void) write(fd, &exit_status, sizeof (exit_status)); |
|
312 |
||
313 |
(void) close(fd); |
|
314 |
||
315 |
if ((fd = open("/dev/null", O_RDWR)) >= 0) { |
|
316 |
(void) fcntl(fd, F_DUP2FD, STDIN_FILENO); |
|
317 |
(void) fcntl(fd, F_DUP2FD, STDOUT_FILENO); |
|
318 |
(void) fcntl(fd, F_DUP2FD, STDERR_FILENO); |
|
319 |
(void) close(fd); |
|
320 |
} |
|
321 |
||
322 |
__fini_daemon_priv(PRIV_PROC_FORK, PRIV_PROC_EXEC, PRIV_PROC_SESSION, |
|
323 |
PRIV_FILE_LINK_ANY, PRIV_PROC_INFO, NULL); |
|
324 |
} |
|
325 |
||
6139
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
326 |
/* |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
327 |
* smbd_service_init |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
328 |
*/ |
5331 | 329 |
static int |
330 |
smbd_service_init(void) |
|
331 |
{ |
|
6432
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
332 |
int rc; |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
333 |
char resource_domain[SMB_PI_MAX_DOMAIN]; |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
334 |
char fqdn[MAXHOSTNAMELEN]; |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
335 |
|
5331 | 336 |
smbd.s_drv_fd = -1; |
337 |
||
6139
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
338 |
if ((mkdir(SMB_DBDIR, 0700) < 0) && (errno != EEXIST)) { |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
339 |
smbd_report("mkdir %s: %s", SMB_DBDIR, strerror(errno)); |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
340 |
return (1); |
5331 | 341 |
} |
342 |
||
6139
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
343 |
if ((rc = smb_ccache_init(SMB_VARRUN_DIR, SMB_CCACHE_FILE)) != 0) { |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
344 |
if (rc == -1) |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
345 |
smbd_report("mkdir %s: %s", SMB_VARRUN_DIR, |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
346 |
strerror(errno)); |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
347 |
else |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
348 |
smbd_report("unable to set KRB5CCNAME"); |
5331 | 349 |
return (1); |
350 |
} |
|
351 |
||
6139
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
352 |
|
5331 | 353 |
(void) oem_language_set("english"); |
354 |
||
6432
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
355 |
if (!smb_wka_init()) { |
5331 | 356 |
smbd_report("out of memory"); |
357 |
return (1); |
|
358 |
} |
|
359 |
||
6432
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
360 |
if (smb_nicmon_start(SMBD_DEFAULT_INSTANCE_FMRI) != 0) |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
361 |
smbd_report("NIC monitoring failed to start"); |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
362 |
|
7348
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
363 |
dns_msgid_init(); |
5331 | 364 |
smbrdr_init(); |
365 |
||
5772
237ac22142fe
6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents:
5521
diff
changeset
|
366 |
if (smb_netbios_start() != 0) |
237ac22142fe
6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents:
5521
diff
changeset
|
367 |
smbd_report("NetBIOS services failed to start"); |
237ac22142fe
6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents:
5521
diff
changeset
|
368 |
else |
237ac22142fe
6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents:
5521
diff
changeset
|
369 |
smbd_report("NetBIOS services started"); |
237ac22142fe
6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents:
5521
diff
changeset
|
370 |
|
5331 | 371 |
if (smb_netlogon_init() != 0) { |
372 |
smbd_report("netlogon initialization failed"); |
|
373 |
return (1); |
|
374 |
} |
|
375 |
||
5772
237ac22142fe
6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents:
5521
diff
changeset
|
376 |
(void) smb_getdomainname(resource_domain, SMB_PI_MAX_DOMAIN); |
5331 | 377 |
(void) utf8_strupr(resource_domain); |
378 |
||
379 |
/* Get the ID map client handle */ |
|
380 |
if ((rc = smb_idmap_start()) != 0) { |
|
381 |
smbd_report("no idmap handle"); |
|
382 |
return (rc); |
|
383 |
} |
|
384 |
||
6432
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
385 |
smbd.s_secmode = smb_config_get_secmode(); |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
386 |
if ((rc = nt_domain_init(resource_domain, smbd.s_secmode)) != 0) { |
5772
237ac22142fe
6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents:
5521
diff
changeset
|
387 |
if (rc == SMB_DOMAIN_NOMACHINE_SID) { |
237ac22142fe
6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents:
5521
diff
changeset
|
388 |
smbd_report( |
237ac22142fe
6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents:
5521
diff
changeset
|
389 |
"no machine SID: check idmap configuration"); |
237ac22142fe
6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents:
5521
diff
changeset
|
390 |
return (rc); |
237ac22142fe
6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents:
5521
diff
changeset
|
391 |
} |
5331 | 392 |
} |
393 |
||
7052 | 394 |
smb_ads_init(); |
5331 | 395 |
if ((rc = mlsvc_init()) != 0) { |
396 |
smbd_report("msrpc initialization failed"); |
|
397 |
return (rc); |
|
398 |
} |
|
399 |
||
7348
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
400 |
if (smbd.s_secmode == SMB_SECMODE_DOMAIN) |
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
401 |
if (smbd_locate_dc_start(resource_domain) != 0) |
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
402 |
smbd_report("dc discovery failed %s", strerror(errno)); |
6139
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
403 |
|
6771
2e6e486314b6
6686467 Panic in smb_trans_net_share_enum() while browsing over 200 shares from Mac
jb150015
parents:
6600
diff
changeset
|
404 |
smbd.s_door_lmshr = smb_share_dsrv_start(); |
6432
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
405 |
if (smbd.s_door_lmshr < 0) { |
5331 | 406 |
smbd_report("share initialization failed"); |
407 |
} |
|
408 |
||
6432
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
409 |
smbd.s_door_srv = smb_door_srv_start(); |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
410 |
if (smbd.s_door_srv < 0) |
5331 | 411 |
return (rc); |
412 |
||
413 |
if ((rc = smbd_refresh_init()) != 0) |
|
414 |
return (rc); |
|
415 |
||
6139
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
416 |
if (smb_getfqdomainname(fqdn, MAXHOSTNAMELEN) == 0) |
6600
4e63bcd27ae9
6473755 RFE: Need ability to reconcile oplock and delegation conflicts
as200622
parents:
6432
diff
changeset
|
417 |
(void) dyndns_update_core(fqdn); |
5331 | 418 |
|
419 |
(void) smbd_localtime_init(); |
|
420 |
||
7052 | 421 |
smbd.s_door_opipe = smbd_opipe_dsrv_start(); |
422 |
if (smbd.s_door_opipe < 0) { |
|
423 |
smbd_report("opipe initialization failed %s", |
|
5521
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
424 |
strerror(errno)); |
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
425 |
return (rc); |
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
426 |
} |
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
427 |
|
5772
237ac22142fe
6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents:
5521
diff
changeset
|
428 |
(void) smb_lgrp_start(); |
6030
6bebab7d43d5
6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents:
5772
diff
changeset
|
429 |
|
7052 | 430 |
smb_pwd_init(B_TRUE); |
6030
6bebab7d43d5
6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents:
5772
diff
changeset
|
431 |
|
6432
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
432 |
rc = smbd_kernel_bind(); |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
433 |
if (rc != 0) { |
6139
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
434 |
smbd_report("kernel bind error: %s", strerror(errno)); |
6432
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
435 |
return (rc); |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
436 |
} |
5331 | 437 |
|
7348
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
438 |
if ((rc = smb_shr_start()) != 0) { |
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
439 |
smbd_report("share initialization failed: %s", strerror(errno)); |
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
440 |
return (rc); |
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
441 |
} |
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
442 |
|
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
443 |
return (0); |
5521
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
444 |
} |
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
445 |
|
5331 | 446 |
/* |
447 |
* Close the kernel service and shutdown smbd services. |
|
448 |
* This function is registered with atexit(): ensure that anything |
|
449 |
* called from here is safe to be called multiple times. |
|
450 |
*/ |
|
451 |
static void |
|
452 |
smbd_service_fini(void) |
|
453 |
{ |
|
7052 | 454 |
smbd_opipe_dsrv_stop(); |
6432
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
455 |
smb_wka_fini(); |
5331 | 456 |
smbd_refresh_fini(); |
457 |
smbd_kernel_unbind(); |
|
458 |
smb_door_srv_stop(); |
|
6771
2e6e486314b6
6686467 Panic in smb_trans_net_share_enum() while browsing over 200 shares from Mac
jb150015
parents:
6600
diff
changeset
|
459 |
smb_share_dsrv_stop(); |
7052 | 460 |
smb_shr_stop(); |
5331 | 461 |
smb_nicmon_stop(); |
462 |
smb_idmap_stop(); |
|
5772
237ac22142fe
6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents:
5521
diff
changeset
|
463 |
smb_lgrp_stop(); |
6139
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
464 |
smb_ccache_remove(SMB_CCACHE_PATH); |
6030
6bebab7d43d5
6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents:
5772
diff
changeset
|
465 |
smb_pwd_fini(); |
5521
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
466 |
|
5331 | 467 |
} |
468 |
||
6139
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
469 |
|
5331 | 470 |
/* |
471 |
* smbd_refresh_init() |
|
472 |
* |
|
473 |
* SMB service refresh thread initialization. This thread waits for a |
|
474 |
* refresh event and updates the daemon's view of the configuration |
|
475 |
* before going back to sleep. |
|
476 |
*/ |
|
477 |
static int |
|
478 |
smbd_refresh_init() |
|
479 |
{ |
|
6432
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
480 |
pthread_attr_t tattr; |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
481 |
pthread_condattr_t cattr; |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
482 |
int rc; |
5331 | 483 |
|
484 |
(void) pthread_condattr_init(&cattr); |
|
485 |
(void) pthread_cond_init(&refresh_cond, &cattr); |
|
486 |
(void) pthread_condattr_destroy(&cattr); |
|
487 |
||
488 |
(void) pthread_mutex_init(&refresh_mutex, NULL); |
|
489 |
||
490 |
(void) pthread_attr_init(&tattr); |
|
491 |
(void) pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED); |
|
492 |
rc = pthread_create(&refresh_thr, &tattr, smbd_refresh_monitor, 0); |
|
493 |
(void) pthread_attr_destroy(&tattr); |
|
6432
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
494 |
|
5331 | 495 |
return (rc); |
496 |
} |
|
497 |
||
498 |
/* |
|
499 |
* smbd_refresh_fini() |
|
500 |
* |
|
501 |
* Stop the refresh thread. |
|
502 |
*/ |
|
503 |
static void |
|
504 |
smbd_refresh_fini() |
|
505 |
{ |
|
506 |
(void) pthread_cancel(refresh_thr); |
|
507 |
||
508 |
(void) pthread_cond_destroy(&refresh_cond); |
|
509 |
(void) pthread_mutex_destroy(&refresh_mutex); |
|
510 |
} |
|
511 |
||
512 |
/* |
|
513 |
* smbd_refresh_monitor() |
|
514 |
* |
|
515 |
* Wait for a refresh event. When this thread wakes up, update the |
|
516 |
* smbd configuration from the SMF config information then go back to |
|
517 |
* wait for the next refresh. |
|
518 |
*/ |
|
519 |
/*ARGSUSED*/ |
|
520 |
static void * |
|
521 |
smbd_refresh_monitor(void *arg) |
|
522 |
{ |
|
6432
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
523 |
smb_io_t smb_io; |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
524 |
size_t len; |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
525 |
char *new_dom; |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
526 |
int new_secmod; |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
527 |
char *old_dom; |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
528 |
char fqdn[MAXHOSTNAMELEN]; |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
529 |
int rc = 0; |
5331 | 530 |
|
6771
2e6e486314b6
6686467 Panic in smb_trans_net_share_enum() while browsing over 200 shares from Mac
jb150015
parents:
6600
diff
changeset
|
531 |
bzero(&smb_io, sizeof (smb_io)); |
2e6e486314b6
6686467 Panic in smb_trans_net_share_enum() while browsing over 200 shares from Mac
jb150015
parents:
6600
diff
changeset
|
532 |
smb_io.sio_version = SMB_IOC_VERSION; |
2e6e486314b6
6686467 Panic in smb_trans_net_share_enum() while browsing over 200 shares from Mac
jb150015
parents:
6600
diff
changeset
|
533 |
|
5331 | 534 |
(void) pthread_mutex_lock(&refresh_mutex); |
535 |
while (pthread_cond_wait(&refresh_cond, &refresh_mutex) == 0) { |
|
536 |
/* |
|
537 |
* We've been woken up by a refresh event so go do |
|
538 |
* what is necessary. |
|
539 |
*/ |
|
7052 | 540 |
smb_ads_refresh(); |
6139
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
541 |
smb_ccache_remove(SMB_CCACHE_PATH); |
6432
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
542 |
|
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
543 |
if ((rc = smb_getfqdomainname(fqdn, MAXHOSTNAMELEN)) != 0) |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
544 |
smbd_report("failed to get fully qualified domainname"); |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
545 |
|
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
546 |
if (rc == 0) |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
547 |
/* Clear rev zone before creating if list */ |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
548 |
if (dyndns_clear_rev_zone(fqdn) != 0) |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
549 |
smbd_report("failed to clear DNS reverse " |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
550 |
"lookup zone"); |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
551 |
|
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
552 |
/* re-initialize NIC table */ |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
553 |
if (smb_nic_init() != 0) |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
554 |
smbd_report("failed to get NIC information"); |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
555 |
|
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
556 |
smb_netbios_name_reconfig(); |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
557 |
smb_browser_reconfig(); |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
558 |
|
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
559 |
if (rc == 0) |
6600
4e63bcd27ae9
6473755 RFE: Need ability to reconcile oplock and delegation conflicts
as200622
parents:
6432
diff
changeset
|
560 |
if (dyndns_update_core(fqdn) != 0) |
6432
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
561 |
smbd_report("failed to update dynamic DNS"); |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
562 |
|
6139
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
563 |
smb_set_netlogon_cred(); |
6432
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
564 |
|
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
565 |
smb_load_kconfig(&smb_io.sio_data.cfg); |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
566 |
new_dom = smb_io.sio_data.cfg.skc_resource_domain; |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
567 |
old_dom = smbd.s_kcfg.skc_resource_domain; |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
568 |
len = strlen(old_dom); |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
569 |
new_secmod = smb_config_get_secmode(); |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
570 |
if ((len != strlen(new_dom)) || |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
571 |
(strncasecmp(new_dom, old_dom, len)) || |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
572 |
(new_secmod != smbd.s_secmode) || |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
573 |
(smbd.s_drv_fd == -1)) { |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
574 |
/* |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
575 |
* The active sessions have to be disconnected. |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
576 |
*/ |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
577 |
smbd_kernel_unbind(); |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
578 |
if (smbd_kernel_bind()) { |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
579 |
smbd_report("kernel bind error: %s", |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
580 |
strerror(errno)); |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
581 |
} |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
582 |
continue; |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
583 |
} |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
584 |
|
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
585 |
bcopy(&smb_io.sio_data.cfg, &smbd.s_kcfg, sizeof (smbd.s_kcfg)); |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
586 |
if (ioctl(smbd.s_drv_fd, SMB_IOC_CONFIG, &smb_io) < 0) { |
5331 | 587 |
smbd_report("configuration update ioctl: %s", |
588 |
strerror(errno)); |
|
589 |
} |
|
590 |
} |
|
591 |
return (NULL); |
|
592 |
} |
|
593 |
||
594 |
||
595 |
/* |
|
596 |
* If the door has already been opened by another process (non-zero pid |
|
597 |
* in target), we assume that another smbd is already running. If there |
|
598 |
* is a race here, it will be caught later when smbsrv is opened because |
|
599 |
* only one process is allowed to open the device at a time. |
|
600 |
*/ |
|
601 |
static int |
|
602 |
smbd_already_running(void) |
|
603 |
{ |
|
604 |
door_info_t info; |
|
605 |
int door; |
|
606 |
||
6139
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
607 |
if ((door = open(SMB_DR_SVC_NAME, O_RDONLY)) < 0) |
5331 | 608 |
return (0); |
609 |
||
610 |
if (door_info(door, &info) < 0) |
|
611 |
return (0); |
|
612 |
||
613 |
if (info.di_target > 0) { |
|
614 |
smbd_report("already running: pid %ld\n", info.di_target); |
|
615 |
(void) close(door); |
|
616 |
return (1); |
|
617 |
} |
|
618 |
||
619 |
(void) close(door); |
|
620 |
return (0); |
|
621 |
} |
|
622 |
||
6139
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
623 |
/* |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
624 |
* smbd_kernel_bind |
6432
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
625 |
* |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
626 |
* This function open the smbsrv device and start the kernel service. |
6139
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
627 |
*/ |
5331 | 628 |
static int |
6432
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
629 |
smbd_kernel_bind(void) |
5331 | 630 |
{ |
7826
31ae58c8daeb
6758621 Duplication of lines in smbd_main.c that lead to the creation of 4 listeners instead of 2
jose borrego <Jose.Borrego@Sun.COM>
parents:
7348
diff
changeset
|
631 |
pthread_attr_t tattr; |
6139
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
632 |
smb_io_t smb_io; |
7826
31ae58c8daeb
6758621 Duplication of lines in smbd_main.c that lead to the creation of 4 listeners instead of 2
jose borrego <Jose.Borrego@Sun.COM>
parents:
7348
diff
changeset
|
633 |
int rc1; |
31ae58c8daeb
6758621 Duplication of lines in smbd_main.c that lead to the creation of 4 listeners instead of 2
jose borrego <Jose.Borrego@Sun.COM>
parents:
7348
diff
changeset
|
634 |
int rc2; |
6139
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
635 |
int rc; |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
636 |
|
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
637 |
bzero(&smb_io, sizeof (smb_io)); |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
638 |
smb_io.sio_version = SMB_IOC_VERSION; |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
639 |
|
5331 | 640 |
if (smbd.s_drv_fd != -1) |
641 |
(void) close(smbd.s_drv_fd); |
|
642 |
||
643 |
if ((smbd.s_drv_fd = open(DRV_DEVICE_PATH, 0)) < 0) { |
|
644 |
smbd.s_drv_fd = -1; |
|
6139
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
645 |
return (errno); |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
646 |
} |
6432
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
647 |
smb_load_kconfig(&smbd.s_kcfg); |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
648 |
bcopy(&smbd.s_kcfg, &smb_io.sio_data.cfg, sizeof (smb_io.sio_data.cfg)); |
6139
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
649 |
if (ioctl(smbd.s_drv_fd, SMB_IOC_CONFIG, &smb_io) < 0) { |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
650 |
(void) close(smbd.s_drv_fd); |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
651 |
smbd.s_drv_fd = -1; |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
652 |
return (errno); |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
653 |
} |
7348
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
654 |
smb_io.sio_data.gmtoff = smbd_gmtoff(); |
6139
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
655 |
if (ioctl(smbd.s_drv_fd, SMB_IOC_GMTOFF, &smb_io) < 0) { |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
656 |
(void) close(smbd.s_drv_fd); |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
657 |
smbd.s_drv_fd = -1; |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
658 |
return (errno); |
5331 | 659 |
} |
7052 | 660 |
smb_io.sio_data.start.opipe = smbd.s_door_opipe; |
6432
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
661 |
smb_io.sio_data.start.lmshrd = smbd.s_door_lmshr; |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
662 |
smb_io.sio_data.start.udoor = smbd.s_door_srv; |
6139
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
663 |
if (ioctl(smbd.s_drv_fd, SMB_IOC_START, &smb_io) < 0) { |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
664 |
(void) close(smbd.s_drv_fd); |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
665 |
smbd.s_drv_fd = -1; |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
666 |
return (errno); |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
667 |
} |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
668 |
|
7826
31ae58c8daeb
6758621 Duplication of lines in smbd_main.c that lead to the creation of 4 listeners instead of 2
jose borrego <Jose.Borrego@Sun.COM>
parents:
7348
diff
changeset
|
669 |
(void) pthread_attr_init(&tattr); |
31ae58c8daeb
6758621 Duplication of lines in smbd_main.c that lead to the creation of 4 listeners instead of 2
jose borrego <Jose.Borrego@Sun.COM>
parents:
7348
diff
changeset
|
670 |
(void) pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED); |
31ae58c8daeb
6758621 Duplication of lines in smbd_main.c that lead to the creation of 4 listeners instead of 2
jose borrego <Jose.Borrego@Sun.COM>
parents:
7348
diff
changeset
|
671 |
|
31ae58c8daeb
6758621 Duplication of lines in smbd_main.c that lead to the creation of 4 listeners instead of 2
jose borrego <Jose.Borrego@Sun.COM>
parents:
7348
diff
changeset
|
672 |
rc1 = pthread_create(&nbt_listener, &tattr, smbd_nbt_listener, NULL); |
31ae58c8daeb
6758621 Duplication of lines in smbd_main.c that lead to the creation of 4 listeners instead of 2
jose borrego <Jose.Borrego@Sun.COM>
parents:
7348
diff
changeset
|
673 |
if (rc1 != 0) |
31ae58c8daeb
6758621 Duplication of lines in smbd_main.c that lead to the creation of 4 listeners instead of 2
jose borrego <Jose.Borrego@Sun.COM>
parents:
7348
diff
changeset
|
674 |
smbd_report("unable to start NBT service"); |
31ae58c8daeb
6758621 Duplication of lines in smbd_main.c that lead to the creation of 4 listeners instead of 2
jose borrego <Jose.Borrego@Sun.COM>
parents:
7348
diff
changeset
|
675 |
|
31ae58c8daeb
6758621 Duplication of lines in smbd_main.c that lead to the creation of 4 listeners instead of 2
jose borrego <Jose.Borrego@Sun.COM>
parents:
7348
diff
changeset
|
676 |
rc2 = pthread_create(&tcp_listener, &tattr, smbd_tcp_listener, NULL); |
31ae58c8daeb
6758621 Duplication of lines in smbd_main.c that lead to the creation of 4 listeners instead of 2
jose borrego <Jose.Borrego@Sun.COM>
parents:
7348
diff
changeset
|
677 |
if (rc2 != 0) |
31ae58c8daeb
6758621 Duplication of lines in smbd_main.c that lead to the creation of 4 listeners instead of 2
jose borrego <Jose.Borrego@Sun.COM>
parents:
7348
diff
changeset
|
678 |
smbd_report("unable to start TCP service"); |
31ae58c8daeb
6758621 Duplication of lines in smbd_main.c that lead to the creation of 4 listeners instead of 2
jose borrego <Jose.Borrego@Sun.COM>
parents:
7348
diff
changeset
|
679 |
|
31ae58c8daeb
6758621 Duplication of lines in smbd_main.c that lead to the creation of 4 listeners instead of 2
jose borrego <Jose.Borrego@Sun.COM>
parents:
7348
diff
changeset
|
680 |
(void) pthread_attr_destroy(&tattr); |
31ae58c8daeb
6758621 Duplication of lines in smbd_main.c that lead to the creation of 4 listeners instead of 2
jose borrego <Jose.Borrego@Sun.COM>
parents:
7348
diff
changeset
|
681 |
|
31ae58c8daeb
6758621 Duplication of lines in smbd_main.c that lead to the creation of 4 listeners instead of 2
jose borrego <Jose.Borrego@Sun.COM>
parents:
7348
diff
changeset
|
682 |
rc = rc1; |
31ae58c8daeb
6758621 Duplication of lines in smbd_main.c that lead to the creation of 4 listeners instead of 2
jose borrego <Jose.Borrego@Sun.COM>
parents:
7348
diff
changeset
|
683 |
if (rc == 0) |
31ae58c8daeb
6758621 Duplication of lines in smbd_main.c that lead to the creation of 4 listeners instead of 2
jose borrego <Jose.Borrego@Sun.COM>
parents:
7348
diff
changeset
|
684 |
rc = rc2; |
31ae58c8daeb
6758621 Duplication of lines in smbd_main.c that lead to the creation of 4 listeners instead of 2
jose borrego <Jose.Borrego@Sun.COM>
parents:
7348
diff
changeset
|
685 |
|
6139
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
686 |
if (rc == 0) { |
7826
31ae58c8daeb
6758621 Duplication of lines in smbd_main.c that lead to the creation of 4 listeners instead of 2
jose borrego <Jose.Borrego@Sun.COM>
parents:
7348
diff
changeset
|
687 |
smbd.s_kbound = B_TRUE; |
31ae58c8daeb
6758621 Duplication of lines in smbd_main.c that lead to the creation of 4 listeners instead of 2
jose borrego <Jose.Borrego@Sun.COM>
parents:
7348
diff
changeset
|
688 |
return (0); |
6432
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
689 |
} |
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
690 |
|
6139
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
691 |
(void) close(smbd.s_drv_fd); |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
692 |
smbd.s_drv_fd = -1; |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
693 |
return (rc); |
5331 | 694 |
} |
695 |
||
6139
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
696 |
/* |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
697 |
* smbd_kernel_unbind |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
698 |
*/ |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
699 |
static void |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
700 |
smbd_kernel_unbind(void) |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
701 |
{ |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
702 |
if (smbd.s_drv_fd != -1) { |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
703 |
(void) close(smbd.s_drv_fd); |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
704 |
smbd.s_drv_fd = -1; |
6432
98715880dd9e
6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents:
6139
diff
changeset
|
705 |
smbd.s_kbound = B_FALSE; |
6139
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
706 |
} |
5c743b207bf9
6541120 Configuration is not propagated to SMB kernel module
jb150015
parents:
6030
diff
changeset
|
707 |
} |
5331 | 708 |
|
709 |
/* |
|
710 |
* Initialization of the localtime thread. |
|
711 |
* Returns 0 on success, an error number if thread creation fails. |
|
712 |
*/ |
|
713 |
||
714 |
int |
|
715 |
smbd_localtime_init(void) |
|
716 |
{ |
|
717 |
pthread_attr_t tattr; |
|
718 |
int rc; |
|
719 |
||
720 |
(void) pthread_attr_init(&tattr); |
|
721 |
(void) pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED); |
|
722 |
rc = pthread_create(&localtime_thr, &tattr, smbd_localtime_monitor, 0); |
|
723 |
(void) pthread_attr_destroy(&tattr); |
|
724 |
return (rc); |
|
725 |
} |
|
726 |
||
727 |
/* |
|
728 |
* Local time thread to kernel land. |
|
729 |
* Send local gmtoff to kernel module one time at startup |
|
730 |
* and each time it changes (up to twice a year). |
|
731 |
* Local gmtoff is checked once every 15 minutes and |
|
732 |
* since some timezones are aligned on half and qtr hour boundaries, |
|
733 |
* once an hour would likely suffice. |
|
734 |
*/ |
|
735 |
||
736 |
/*ARGSUSED*/ |
|
737 |
static void * |
|
738 |
smbd_localtime_monitor(void *arg) |
|
739 |
{ |
|
740 |
struct tm local_tm; |
|
7348
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
741 |
time_t secs; |
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
742 |
int32_t gmtoff, last_gmtoff = -1; |
5331 | 743 |
int timeout; |
744 |
||
745 |
for (;;) { |
|
7348
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
746 |
gmtoff = smbd_gmtoff(); |
5331 | 747 |
|
748 |
if ((last_gmtoff != gmtoff) && (smbd.s_drv_fd != -1)) { |
|
749 |
if (ioctl(smbd.s_drv_fd, SMB_IOC_GMTOFF, &gmtoff) < 0) { |
|
750 |
smbd_report("localtime ioctl: %s", |
|
751 |
strerror(errno)); |
|
752 |
} |
|
753 |
} |
|
754 |
||
755 |
/* |
|
756 |
* Align the next iteration on a fifteen minute boundary. |
|
757 |
*/ |
|
758 |
secs = time(0); |
|
759 |
(void) localtime_r(&secs, &local_tm); |
|
760 |
timeout = ((15 - (local_tm.tm_min % 15)) * SECSPERMIN); |
|
761 |
(void) sleep(timeout); |
|
762 |
||
763 |
last_gmtoff = gmtoff; |
|
764 |
} |
|
765 |
||
766 |
/*NOTREACHED*/ |
|
767 |
return (NULL); |
|
768 |
} |
|
769 |
||
7348
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
770 |
/* |
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
771 |
* smbd_gmtoff |
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
772 |
* |
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
773 |
* Determine offset from GMT. If daylight saving time use altzone, |
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
774 |
* otherwise use timezone. |
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
775 |
*/ |
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
776 |
static int32_t |
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
777 |
smbd_gmtoff(void) |
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
778 |
{ |
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
779 |
time_t clock_val; |
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
780 |
struct tm *atm; |
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
781 |
int32_t gmtoff; |
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
782 |
|
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
783 |
(void) time(&clock_val); |
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
784 |
atm = localtime(&clock_val); |
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
785 |
|
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
786 |
gmtoff = (atm->tm_isdst) ? altzone : timezone; |
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
787 |
|
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
788 |
return (gmtoff); |
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
789 |
} |
73b61202d5d6
6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents:
7052
diff
changeset
|
790 |
|
5331 | 791 |
static void |
792 |
smbd_sig_handler(int sigval) |
|
793 |
{ |
|
794 |
if (smbd.s_sigval == 0) |
|
795 |
smbd.s_sigval = sigval; |
|
796 |
} |
|
797 |
||
798 |
/* |
|
799 |
* Set up configuration options and parse the command line. |
|
800 |
* This function will determine if we will run as a daemon |
|
801 |
* or in the foreground. |
|
802 |
* |
|
803 |
* Failure to find a uid or gid results in using the default (0). |
|
804 |
*/ |
|
805 |
static int |
|
806 |
smbd_setup_options(int argc, char *argv[]) |
|
807 |
{ |
|
808 |
struct passwd *pwd; |
|
809 |
struct group *grp; |
|
810 |
int c; |
|
811 |
||
812 |
if ((pwd = getpwnam("root")) != NULL) |
|
813 |
smbd.s_uid = pwd->pw_uid; |
|
814 |
||
815 |
if ((grp = getgrnam("sys")) != NULL) |
|
816 |
smbd.s_gid = grp->gr_gid; |
|
817 |
||
5772
237ac22142fe
6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents:
5521
diff
changeset
|
818 |
smbd.s_fg = smb_config_get_fg_flag(); |
5331 | 819 |
|
820 |
while ((c = getopt(argc, argv, ":f")) != -1) { |
|
821 |
switch (c) { |
|
822 |
case 'f': |
|
823 |
smbd.s_fg = 1; |
|
824 |
break; |
|
825 |
||
826 |
case ':': |
|
827 |
case '?': |
|
828 |
default: |
|
829 |
smbd_usage(stderr); |
|
830 |
return (-1); |
|
831 |
} |
|
832 |
} |
|
833 |
||
834 |
return (0); |
|
835 |
} |
|
836 |
||
837 |
static void |
|
838 |
smbd_usage(FILE *fp) |
|
839 |
{ |
|
840 |
static char *help[] = { |
|
841 |
"-f run program in foreground" |
|
842 |
}; |
|
843 |
||
844 |
int i; |
|
845 |
||
846 |
(void) fprintf(fp, "Usage: %s [-f]\n", smbd.s_pname); |
|
847 |
||
848 |
for (i = 0; i < sizeof (help)/sizeof (help[0]); ++i) |
|
849 |
(void) fprintf(fp, " %s\n", help[i]); |
|
850 |
} |
|
851 |
||
852 |
static void |
|
853 |
smbd_report(const char *fmt, ...) |
|
854 |
{ |
|
855 |
char buf[128]; |
|
856 |
va_list ap; |
|
857 |
||
858 |
if (fmt == NULL) |
|
859 |
return; |
|
860 |
||
861 |
va_start(ap, fmt); |
|
862 |
(void) vsnprintf(buf, 128, fmt, ap); |
|
863 |
va_end(ap); |
|
864 |
||
865 |
(void) fprintf(stderr, "smbd: %s\n", buf); |
|
866 |
} |
|
867 |
||
868 |
/* |
|
869 |
* Enable libumem debugging by default on DEBUG builds. |
|
870 |
*/ |
|
871 |
#ifdef DEBUG |
|
872 |
const char * |
|
873 |
_umem_debug_init(void) |
|
874 |
{ |
|
875 |
return ("default,verbose"); /* $UMEM_DEBUG setting */ |
|
876 |
} |
|
877 |
||
878 |
const char * |
|
879 |
_umem_logging_init(void) |
|
880 |
{ |
|
881 |
return ("fail,contents"); /* $UMEM_LOGGING setting */ |
|
882 |
} |
|
883 |
#endif |