smbd_main.c revision cb174861876aea6950a7ab4ce944aff84b1914cd
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER START
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The contents of this file are subject to the terms of the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Common Development and Distribution License (the "License").
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * You may not use this file except in compliance with the License.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * See the License for the specific language governing permissions
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * and limitations under the License.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * When distributing Covered Code, include this CDDL HEADER in each
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If applicable, add the following below this CDDL HEADER, with the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * fields enclosed by brackets "[]" replaced with your own identifying
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * information: Portions Copyright [yyyy] [name of copyright owner]
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER END
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States#include <smbsrv/smb_door.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define DRV_DEVICE_PATH "/devices/pseudo/smbsrv@0:smbsrv"
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightstatic void *smbd_nbt_listener(void *);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightstatic void *smbd_tcp_listener(void *);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightstatic void *smbd_nbt_receiver(void *);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightstatic void *smbd_tcp_receiver(void *);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int smbd_daemonize_init(void);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void smbd_daemonize_fini(int, int);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightstatic int smb_init_daemon_priv(int, uid_t, gid_t);
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2easstatic int smbd_kernel_bind(void);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void smbd_kernel_unbind(void);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int smbd_already_running(void);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int smbd_service_init(void);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void smbd_service_fini(void);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int smbd_localtime_init(void);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshstatic int smbd_spool_init(void);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int smbd_refresh_init(void);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void smbd_refresh_fini(void);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void *smbd_refresh_monitor(void *);
7f667e74610492ddbce8ce60f52ece95d2401949jose borregostatic void smbd_refresh_dc(void);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightstatic void *smbd_nbt_receiver(void *);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightstatic void *smbd_nbt_listener(void *);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightstatic void *smbd_tcp_receiver(void *);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightstatic void *smbd_tcp_listener(void *);
a4b239dfde5f1d873c730c047e87e5714ebddbb7jose borregostatic int smbd_start_listeners(void);
a4b239dfde5f1d873c730c047e87e5714ebddbb7jose borregostatic void smbd_stop_listeners(void);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightstatic int smbd_kernel_start(void);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightstatic void smbd_fatal_error(const char *);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United Statesstatic cond_t listener_cv;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United Statesstatic mutex_t listener_mutex;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States/*
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * Mutex to ensure that smbd_service_fini() and smbd_service_init()
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * are atomic w.r.t. one another. Otherwise, if a shutdown begins
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * before initialization is complete, resources can get deallocated
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * while initialization threads are still using them.
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States */
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United Statesstatic mutex_t smbd_service_mutex;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United Statesstatic cond_t smbd_service_cv;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Use SMF error codes only on return or exit.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw openlog(smbd.s_pname, LOG_PID | LOG_NOWAIT, LOG_DAEMON);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh * Raise the file descriptor limit to accommodate simultaneous user
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh smbd_report("Failed to raise file descriptor limit"
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) sigaction(SIGABRT, &act, NULL);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (smbd_service_init() != 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * "pfd" is a pipe descriptor -- any fatal errors
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * during subsequent initialization of the child
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * process should be written to this pipe and the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * parent will report this error as the exit status.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (smbd_service_init() != 0) {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) atexit(smb_kmod_stop);
8d7e41661dc4633488e93b13363137523ce59977jose borrego if (smbd.s_sigval == 0 && smbd.s_refreshes == 0)
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States case SIGABRT:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Typically SIGINT or SIGTERM.
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright return ((smbd.s_fatal_error) ? SMF_EXIT_ERR_FATAL : SMF_EXIT_OK);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This function will fork off a child process,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * from which only the child will return.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Use SMF error codes only on exit.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Reset privileges to the minimum set required. We continue
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * to run as root to create and access files in /var.
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright rc = smb_init_daemon_priv(PU_RESETGROUPS, smbd.s_uid, smbd.s_gid);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (rc != 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Block all signals prior to the fork and leave them blocked in the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * parent so we don't get in a situation where the parent gets SIGINT
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * and returns non-zero exit status and the child is actually running.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * In the child, restore the signal mask once we've done our setsid().
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw openlog(smbd.s_pname, LOG_PID | LOG_NOWAIT, LOG_DAEMON);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If we're the parent process, wait for either the child to send us
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the appropriate exit status over the pipe or for the read to fail
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * (presumably with 0 for EOF if our child terminated abnormally).
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If the read fails, exit with either the child's exit status if it
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * exited or with SMF_EXIT_ERR_FATAL if it died from a fatal signal.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (pid != 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (read(pfds[0], &status, sizeof (status)) == sizeof (status))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (waitpid(pid, &status, 0) == pid && WIFEXITED(status))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw openlog(smbd.s_pname, LOG_PID | LOG_NOWAIT, LOG_DAEMON);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * This function is based on __init_daemon_priv() and replaces
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * __init_daemon_priv() since we want smbd to have all privileges so that it
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * can execute map/unmap commands with all privileges during share
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * connection/disconnection. Unused privileges are disabled until command
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * execution. The permitted and the limit set contains all privileges. The
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * inheritable set contains no privileges.
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightstatic const char daemon_cp[] = "/var/tmp/core.%f.%t";
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightsmb_init_daemon_priv(int flags, uid_t uid, gid_t gid)
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * This is not a significant failure: it allows us to start programs
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * with sufficient privileges and with the proper uid. We don't
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * care enough about the extra groups in that case.
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright (void) setppriv(PRIV_SET, PRIV_EFFECTIVE, perm);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright /* Now reset suid and euid */
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if (uid != (uid_t)-1 && setreuid(uid, uid) != 0)
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright ret = setppriv(PRIV_SET, PRIV_INHERITABLE, perm);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if (core_get_process_path(buf, sizeof (buf), getpid()) == 0 &&
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if ((uid == (uid_t)-1 ? geteuid() : uid) == 0) {
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright (void) core_set_process_path(root_cp, sizeof (root_cp),
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * Most privileges, except the ones that are required for smbd, are turn off
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * in the effective set. They will be turn on when needed for command
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * execution during share connection/disconnection.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Now that we're running, if a pipe fd was specified, write an exit
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * status to it to indicate that our parent process can safely detach.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Then proceed to loading the remaining non-built-in modules.
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright /* list of privileges for smbd */
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) priv_addset(pset, PRIV_SYS_MOUNT);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright /* turn off unneeded privileges */
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright (void) setppriv(PRIV_OFF, PRIV_EFFECTIVE, pset);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright /* reenable core dumps */
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * smbd_service_init
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States static struct dir {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States char *name;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States int perm;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States } dir[] = {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States { SMB_DBDIR, 0700 },
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States { SMB_CVOL, 0755 },
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States { SMB_SYSROOT, 0755 },
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States { SMB_SYSTEM32, 0755 },
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States { SMB_VSS, 0755 }
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States };
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States int rc, i;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_lock(&smbd_service_mutex);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States for (i = 0; i < sizeof (dir)/sizeof (dir[0]); ++i) {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if ((mkdir(dir[i].name, dir[i].perm) < 0) &&
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (errno != EEXIST)) {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smbd_report("mkdir %s: %s", dir[i].name,
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States strerror(errno));
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_unlock(&smbd_service_mutex);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States return (-1);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States }
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb if ((rc = smb_ccache_init(SMB_VARRUN_DIR, SMB_CCACHE_FILE)) != 0) {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_unlock(&smbd_service_mutex);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States return (-1);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smbd.s_loghd = smb_log_create(SMBD_LOGSIZE, SMBD_LOGNAME);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if (smbd_nicmon_start(SMBD_DEFAULT_INSTANCE_FMRI) != 0)
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright if ((rc = smb_domain_init(smbd.s_secmode)) != 0) {
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as "no machine SID: check idmap configuration");
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_unlock(&smbd_service_mutex);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States return (-1);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (mlsvc_init() != 0) {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_unlock(&smbd_service_mutex);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States return (-1);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego smbd_report("dc discovery failed %s", strerror(errno));
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smbd.s_door_srv = smbd_door_start();
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smbd.s_door_opipe = smbd_opipe_start();
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (smbd.s_door_srv < 0 || smbd.s_door_opipe < 0) {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smbd_report("door initialization failed %s", strerror(errno));
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_unlock(&smbd_service_mutex);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States return (-1);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States }
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (smbd_refresh_init() != 0) {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_unlock(&smbd_service_mutex);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States return (-1);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States }
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (smb_shr_start() != 0) {
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States smbd_report("share initialization failed: %s", strerror(errno));
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_unlock(&smbd_service_mutex);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States return (-1);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smbd.s_door_lmshr = smbd_share_start();
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (smbd.s_door_lmshr < 0)
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States smbd_report("share initialization failed");
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (smbd_kernel_bind() != 0) {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_unlock(&smbd_service_mutex);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States return (-1);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (smb_shr_load() != 0) {
8d7e41661dc4633488e93b13363137523ce59977jose borrego smbd_report("failed to start loading shares: %s",
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_unlock(&smbd_service_mutex);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States return (-1);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh smbd_report("failed to start print monitor: %s",
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smbd.s_initialized = B_TRUE;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smbd_report("service initialized");
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) cond_signal(&smbd_service_cv);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_unlock(&smbd_service_mutex);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * Shutdown smbd and smbsrv kernel services.
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States *
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * Shutdown will not begin until initialization has completed.
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * Only one thread is allowed to perform the shutdown. Other
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * threads will be blocked on fini_in_progress until the process
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * has exited.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States static uint_t fini_in_progress;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_lock(&smbd_service_mutex);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States while (!smbd.s_initialized)
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) cond_wait(&smbd_service_cv, &smbd_service_mutex);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (atomic_swap_uint(&fini_in_progress, 1) != 0) {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States while (fini_in_progress)
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) cond_wait(&smbd_service_cv, &smbd_service_mutex);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States /*NOTREACHED*/
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States }
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smbd.s_shutting_down = B_TRUE;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smbd_report("service shutting down");
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smb_kmod_stop();
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smb_logon_abort();
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smb_lgrp_stop();
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smbd_opipe_stop();
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smbd_door_stop();
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smbd_share_stop();
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smbd.s_initialized = B_FALSE;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smbd_report("service terminated");
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_unlock(&smbd_service_mutex);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States exit((smbd.s_fatal_error) ? SMF_EXIT_ERR_FATAL : SMF_EXIT_OK);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smbd_refresh_init()
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB service refresh thread initialization. This thread waits for a
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * refresh event and updates the daemon's view of the configuration
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * before going back to sleep.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw rc = pthread_create(&refresh_thr, &tattr, smbd_refresh_monitor, 0);
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas return (rc);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smbd_refresh_fini()
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Stop the refresh thread.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (pthread_self() != refresh_thr) {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) pthread_cancel(refresh_thr);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) pthread_cond_destroy(&refresh_cond);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) pthread_mutex_destroy(&refresh_mutex);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smbd_refresh_monitor()
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Wait for a refresh event. When this thread wakes up, update the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smbd configuration from the SMF config information then go back to
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * wait for the next refresh.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*ARGSUSED*/
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void *
8d7e41661dc4633488e93b13363137523ce59977jose borrego while ((atomic_swap_uint(&smbd.s_refreshes, 0) == 0) &&
8d7e41661dc4633488e93b13363137523ce59977jose borrego (void) pthread_cond_wait(&refresh_cond, &refresh_mutex);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smbd_service_fini();
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States /*NOTREACHED*/
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_lock(&smbd_service_mutex);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * We've been woken up by a refresh event so go do
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * what is necessary.
8d7e41661dc4633488e93b13363137523ce59977jose borrego * Start the dyndns thread, if required.
8d7e41661dc4633488e93b13363137523ce59977jose borrego * Clear the DNS zones for the existing interfaces
8d7e41661dc4633488e93b13363137523ce59977jose borrego * before updating the NIC interface list.
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_unlock(&smbd_service_mutex);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
8d7e41661dc4633488e93b13363137523ce59977jose borrego * Restart required because the domain changed
8d7e41661dc4633488e93b13363137523ce59977jose borrego * or the credential chain setup failed.
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States "unable to restart smb/server. "
8d7e41661dc4633488e93b13363137523ce59977jose borrego "Run 'svcs -xv smb/server' for more "
8d7e41661dc4633488e93b13363137523ce59977jose borrego "information.");
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smbd_service_fini();
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States /*NOTREACHED*/
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if ((error = smbd_kernel_bind()) == 0)
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego * Update DC information on a refresh.
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego if (smb_config_get_secmode() != SMB_SECMODE_DOMAIN)
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego if (smb_getfqdomainname(fqdomain, MAXHOSTNAMELEN))
8d7e41661dc4633488e93b13363137523ce59977jose borrego syslog(LOG_ERR, "invalid security mode: %d", secmode);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States/*
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * The service is online if initialization is complete and shutdown
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * has not begun.
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States */
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United Statesboolean_t
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United Statessmbd_online(void)
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States{
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States return (smbd.s_initialized && !smbd.s_shutting_down);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States}
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If the door has already been opened by another process (non-zero pid
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * in target), we assume that another smbd is already running. If there
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * is a race here, it will be caught later when smbsrv is opened because
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * only one process is allowed to open the device at a time.
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if ((door = open(SMBD_DOOR_NAME, O_RDONLY)) < 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smbd_report("already running: pid %ld\n", info.di_target);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * smbd_kernel_bind
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas * This function open the smbsrv device and start the kernel service.
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if ((rc = smb_kmod_bind()) == 0) {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (rc != 0)
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smbd_report("kernel bind error: %s", strerror(errno));
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright rc = smb_kmod_start(smbd.s_door_opipe, smbd.s_door_lmshr,
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * smbd_kernel_unbind
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbstatic void
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh * Initialization of the spool thread.
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh * Returns 0 on success, an error number if thread creation fails.
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh (void) pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh rc = pthread_create(&smbd_spool_thr, &tattr, smbd_spool_monitor, 0);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh * This user thread blocks waiting for close print file
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh * in the kernel. It then uses the data returned from the ioctl
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh * to copy the spool file into the cups spooler.
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh * This function is really only used by Vista and Win7 clients,
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh * other versions of windows create only a zero size file and this
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh * be removed by spoolss_copy_spool_file function.
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh while (!smbd.s_shutting_down && (error_retry_cnt > 0)) {
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh if (smb_kmod_get_spool_doc(&spool_num, username,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Initialization of the localtime thread.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Returns 0 on success, an error number if thread creation fails.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw rc = pthread_create(&localtime_thr, &tattr, smbd_localtime_monitor, 0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Local time thread to kernel land.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Send local gmtoff to kernel module one time at startup
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * and each time it changes (up to twice a year).
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Local gmtoff is checked once every 15 minutes and
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * since some timezones are aligned on half and qtr hour boundaries,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * once an hour would likely suffice.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*ARGSUSED*/
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw for (;;) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Align the next iteration on a fifteen minute boundary.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*NOTREACHED*/
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * smbd_gmtoff
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * Determine offset from GMT. If daylight saving time use altzone,
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * otherwise use timezone.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void
8d7e41661dc4633488e93b13363137523ce59977jose borrego (void) atomic_swap_uint(&smbd.s_sigval, sigval);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Set up configuration options and parse the command line.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This function will determine if we will run as a daemon
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * or in the foreground.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Failure to find a uid or gid results in using the default (0).
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw switch (c) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (-1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw static char *help[] = {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw "-f run program in foreground"
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void
a4b239dfde5f1d873c730c047e87e5714ebddbb7jose borrego rc1 = pthread_create(&smbd.s_nbt_listener_id, &tattr,
a4b239dfde5f1d873c730c047e87e5714ebddbb7jose borrego rc2 = pthread_create(&smbd.s_tcp_listener_id, &tattr,
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States/*
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * Stop the listener threads. In an attempt to ensure that the listener
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * threads get the signal, we use the timed wait loop to harass the
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * threads into terminating. Then, if they are still running, we make
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * one final attempt to deliver the signal before calling thread join
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * to wait for them. Note: if these threads don't terminate, smbd will
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * hang here and SMF will probably end up killing the contract.
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States */
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States void *status;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States timestruc_t delay;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States int rc = 0;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_lock(&listener_mutex);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States while ((smbd.s_nbt_listener_running || smbd.s_tcp_listener_running) &&
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (rc != ETIME)) {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (smbd.s_nbt_listener_running)
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) pthread_kill(smbd.s_nbt_listener_id, SIGTERM);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (smbd.s_tcp_listener_running)
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) pthread_kill(smbd.s_tcp_listener_id, SIGTERM);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States delay.tv_sec = 3;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States delay.tv_nsec = 0;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States rc = cond_reltimedwait(&listener_cv, &listener_mutex, &delay);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States }
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_unlock(&listener_mutex);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States syslog(LOG_WARNING, "NBT listener still running");
a4b239dfde5f1d873c730c047e87e5714ebddbb7jose borrego (void) pthread_kill(smbd.s_nbt_listener_id, SIGTERM);
a4b239dfde5f1d873c730c047e87e5714ebddbb7jose borrego (void) pthread_join(smbd.s_nbt_listener_id, &status);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States syslog(LOG_WARNING, "TCP listener still running");
a4b239dfde5f1d873c730c047e87e5714ebddbb7jose borrego (void) pthread_kill(smbd.s_tcp_listener_id, SIGTERM);
a4b239dfde5f1d873c730c047e87e5714ebddbb7jose borrego (void) pthread_join(smbd.s_tcp_listener_id, &status);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * Perform fatal error exit.
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightstatic void *
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightstatic void *
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright (void) pthread_sigmask(SIG_SETMASK, &set, &oset);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright (void) pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright error = pthread_create(&tid, &tattr, smbd_nbt_receiver, NULL);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright smbd_fatal_error("NBT listener thread terminated unexpectedly");
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_lock(&listener_mutex);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smbd.s_nbt_listener_running = B_FALSE;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) cond_broadcast(&listener_cv);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_unlock(&listener_mutex);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightstatic void *
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightstatic void *
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright (void) pthread_sigmask(SIG_SETMASK, &set, &oset);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright (void) pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright error = pthread_create(&tid, &tattr, smbd_tcp_receiver, NULL);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright smbd_fatal_error("TCP listener thread terminated unexpectedly");
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_lock(&listener_mutex);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smbd.s_tcp_listener_running = B_FALSE;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) cond_broadcast(&listener_cv);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_unlock(&listener_mutex);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Enable libumem debugging by default on DEBUG builds.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwconst char *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwconst char *