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