smbd_main.c revision b819cea2f73f98c5662230cc9affc8cc84f77fcf
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.
83d2dfe69259e79314662cf95e6d1f9103dcffe2Gordon Ross * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States#include <smbsrv/smb_door.h>
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);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintoshstatic void smbd_localtime_init(void);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintoshstatic void smbd_dyndns_init(void);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintoshstatic void smbd_load_shares(void);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rossstatic void *smbd_share_loader(void *);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rossstatic void smbd_refresh_handler(void);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightstatic int smbd_kernel_start(void);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Use SMF error codes only on return or exit.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw openlog(smbd.s_pname, LOG_PID | LOG_NOWAIT, LOG_DAEMON);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross /* Can't manipulate privileges in daemonize. */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#else /* FKSMBD */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#endif /* FKSMBD */
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh * Raise the file descriptor limit to accommodate simultaneous user
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh smbd_report("Failed to raise file descriptor limit"
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Block async signals in all threads.
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) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Typically SIGINT or SIGTERM.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Allow termination signals while shutting down.
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
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Stop for a debugger attach here, which is after the
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * fork() etc. in smb_daemonize_init()
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross smbd_report("pid %d stop for debugger attach", smbd.s_pid);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross smbd_report("smbd starting, pid %d", smbd.s_pid);
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 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 return (-1);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smbd_report("print service %savailable", (rc == 0) ? "" : "un");
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if (smbd_nicmon_start(SMBD_DEFAULT_INSTANCE_FMRI) != 0)
83d2dfe69259e79314662cf95e6d1f9103dcffe2Gordon Ross if (smb_config_getbool(SMB_CI_NETBIOS_ENABLE) == 0)
83d2dfe69259e79314662cf95e6d1f9103dcffe2Gordon Ross else if (smb_netbios_start() != 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 return (-1);
1fdeec650620e8498c06f832ea4bd2292f7e9632joyce mcintosh smbd_report("DC monitor initialization failed %s",
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (mlsvc_init() != 0) {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States return (-1);
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 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 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");
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross /* Open the driver, load the kernel config. */
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (smbd_kernel_bind() != 0) {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States return (-1);
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 * Shutdown smbd and smbsrv kernel services.
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States *
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Called only by the main thread.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void
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");
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Called when SMF sends us a SIGHUP. Update the smbd configuration
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh * from SMF and check for changes that require service reconfiguration.
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Clear the DNS zones for the existing interfaces
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * before updating the NIC interface list.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross /* This reloads the in-kernel config. */
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
1fdeec650620e8498c06f832ea4bd2292f7e9632joyce mcintosh * Wait until the service is online. Provided for threads that
1fdeec650620e8498c06f832ea4bd2292f7e9632joyce mcintosh * should wait until the service has been fully initialized before
1fdeec650620e8498c06f832ea4bd2292f7e9632joyce mcintosh * they start performing operations.
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh (void) fprintf(stderr, "%s: online\n", text);
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.
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
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh * If smbsrv is already bound, reload the configuration and update smbsrv.
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh * Otherwise, open the smbsrv device and start the kernel service.
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smbd_report("kernel configuration update failed: %s",
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if ((rc = smb_kmod_bind()) == 0) {
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross smbd_report("kernel bind error: %s", strerror(rc));
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross smbd_report("kernel config ioctl error: %s", strerror(rc));
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross smbd_report("kernel gmtoff ioctl error: %s", strerror(rc));
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright rc = smb_kmod_start(smbd.s_door_opipe, smbd.s_door_lmshr,
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross smbd_report("kernel start ioctl error: %s", strerror(rc));
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * smbd_kernel_unbind
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbstatic void
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh * Create the Dynamic DNS publisher thread.
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh (void) pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh rc = pthread_create(&tid, &attr, dyndns_publisher, NULL);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smbd_report("unable to start dyndns publisher: %s",
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh * Launches a thread to populate the share cache by share information
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh * stored in sharemgr
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh (void) pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross rc = pthread_create(&tid, &attr, smbd_share_loader, NULL);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smbd_report("unable to load disk shares: %s", strerror(errno));
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rossstatic void *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Initialization of the localtime thread.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Returns 0 on success, an error number if thread creation fails.
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh (void) pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh rc = pthread_create(&smbd.s_localtime_tid, &attr,
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smbd_report("unable to monitor localtime: %s", strerror(errno));
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh * Send local gmtoff to the kernel module one time at startup and each
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh * time it changes (up to twice a year).
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh * Local gmtoff is checked once every 15 minutes since some timezones
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh * are aligned on half and quarter hour boundaries.
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.
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).
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross while ((c = getopt(argc, argv, ":dfs")) != -1) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw switch (c) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (-1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw static char *help[] = {
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross "-d enable debug messages"
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw "-f run program in foreground"
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Enable libumem debugging by default on DEBUG builds.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwconst char *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwconst char *