da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER START
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
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 *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * or http://www.opensolaris.org/os/licensing.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * See the License for the specific language governing permissions
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * and limitations under the License.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
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 *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER END
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <sys/types.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <sys/stat.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <sys/ioccom.h>
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright#include <sys/corectl.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <stdio.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <string.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <strings.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <stdlib.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <unistd.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <stdarg.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <fcntl.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <wait.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <signal.h>
8d7e41661dc4633488e93b13363137523ce59977jose borrego#include <atomic.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <libscf.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <limits.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <priv_utils.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <door.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <errno.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <pthread.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <time.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <libscf.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <zone.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <libgen.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <pwd.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <grp.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States#include <smbsrv/smb_door.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <smbsrv/smb_ioctl.h>
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown#include <smbsrv/string.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <smbsrv/libsmb.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <smbsrv/libsmbns.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <smbsrv/libmlsvc.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include "smbd.h"
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#define SECSPERMIN 60
1fdeec650620e8498c06f832ea4bd2292f7e9632joyce mcintosh#define SMBD_ONLINE_WAIT_INTERVAL 10
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh#define SMBD_REFRESH_INTERVAL 10
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define SMB_DBDIR "/var/smb"
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
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);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2easstatic int smbd_kernel_bind(void);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void smbd_kernel_unbind(void);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int smbd_already_running(void);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int smbd_service_init(void);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void smbd_service_fini(void);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int smbd_setup_options(int argc, char *argv[]);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void smbd_usage(FILE *fp);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borregostatic int32_t smbd_gmtoff(void);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintoshstatic void smbd_localtime_init(void);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void *smbd_localtime_monitor(void *arg);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintoshstatic void smbd_dyndns_init(void);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintoshstatic void smbd_load_shares(void);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rossstatic void *smbd_share_loader(void *);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rossstatic void smbd_refresh_handler(void);
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightstatic int smbd_kernel_start(void);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbsmbd_t smbd;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Use SMF error codes only on return or exit.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwint
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwmain(int argc, char *argv[])
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas sigset_t set;
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas uid_t uid;
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas int pfd = -1;
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross int sigval;
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh struct rlimit rl;
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh int orig_limit;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#ifdef FKSMBD
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross fksmbd_init();
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#endif
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smbd.s_pname = basename(argv[0]);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw openlog(smbd.s_pname, LOG_PID | LOG_NOWAIT, LOG_DAEMON);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (smbd_setup_options(argc, argv) != 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SMF_EXIT_ERR_FATAL);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if ((uid = getuid()) != smbd.s_uid) {
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#ifdef FKSMBD
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross /* Can't manipulate privileges in daemonize. */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross if (smbd.s_fg == 0) {
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross smbd.s_fg = 1;
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross smbd_report("user %d (forced -f)", uid);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross }
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#else /* FKSMBD */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smbd_report("user %d: %s", uid, strerror(EPERM));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SMF_EXIT_ERR_FATAL);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#endif /* FKSMBD */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (is_system_labeled()) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smbd_report("Trusted Extensions not supported");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SMF_EXIT_ERR_FATAL);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (smbd_already_running())
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SMF_EXIT_OK);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh /*
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh * Raise the file descriptor limit to accommodate simultaneous user
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh * authentications/file access.
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh */
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh if ((getrlimit(RLIMIT_NOFILE, &rl) == 0) &&
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh (rl.rlim_cur < rl.rlim_max)) {
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh orig_limit = rl.rlim_cur;
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh rl.rlim_cur = rl.rlim_max;
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh if (setrlimit(RLIMIT_NOFILE, &rl) != 0)
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh smbd_report("Failed to raise file descriptor limit"
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh " from %d to %d", orig_limit, rl.rlim_cur);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh }
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross /*
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Block async signals in all threads.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross (void) sigemptyset(&set);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross (void) sigaddset(&set, SIGHUP);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross (void) sigaddset(&set, SIGINT);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross (void) sigaddset(&set, SIGQUIT);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross (void) sigaddset(&set, SIGPIPE);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross (void) sigaddset(&set, SIGTERM);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross (void) sigaddset(&set, SIGUSR1);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross (void) sigaddset(&set, SIGUSR2);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross (void) sigprocmask(SIG_SETMASK, &set, NULL);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (smbd.s_fg) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (smbd_service_init() != 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smbd_report("service initialization failed");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw exit(SMF_EXIT_ERR_FATAL);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw } else {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
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 */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw pfd = smbd_daemonize_init();
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (smbd_service_init() != 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smbd_report("daemon initialization failed");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw exit(SMF_EXIT_ERR_FATAL);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smbd_daemonize_fini(pfd, SMF_EXIT_OK);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
8d7e41661dc4633488e93b13363137523ce59977jose borrego while (!smbd.s_shutting_down) {
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross sigval = sigwait(&set);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
3db3f65c6274eb042354801a308c8e9bc4994553amw switch (sigval) {
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross case -1:
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross syslog(LOG_DEBUG, "sigwait failed: %s",
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross strerror(errno));
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross break;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case SIGPIPE:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw break;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case SIGHUP:
8d7e41661dc4633488e93b13363137523ce59977jose borrego syslog(LOG_DEBUG, "refresh requested");
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross smbd_refresh_handler();
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw break;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright case SIGUSR1:
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross syslog(LOG_DEBUG, "SIGUSR1 ignored");
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright break;
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw default:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Typically SIGINT or SIGTERM.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
8d7e41661dc4633488e93b13363137523ce59977jose borrego smbd.s_shutting_down = B_TRUE;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw break;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross /*
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Allow termination signals while shutting down.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross (void) sigemptyset(&set);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross if (smbd.s_fg) {
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross (void) sigaddset(&set, SIGHUP);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross (void) sigaddset(&set, SIGINT);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross }
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross (void) sigaddset(&set, SIGTERM);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross (void) sigprocmask(SIG_UNBLOCK, &set, NULL);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smbd_service_fini();
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright return ((smbd.s_fatal_error) ? SMF_EXIT_ERR_FATAL : SMF_EXIT_OK);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This function will fork off a child process,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * from which only the child will return.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Use SMF error codes only on exit.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmbd_daemonize_init(void)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int status, pfds[2];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sigset_t set, oset;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw pid_t pid;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int rc;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Reset privileges to the minimum set required. We continue
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * to run as root to create and access files in /var.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright rc = smb_init_daemon_priv(PU_RESETGROUPS, smbd.s_uid, smbd.s_gid);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (rc != 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smbd_report("insufficient privileges");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw exit(SMF_EXIT_ERR_FATAL);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
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 */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) sigfillset(&set);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) sigdelset(&set, SIGABRT);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) sigprocmask(SIG_BLOCK, &set, &oset);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (pipe(pfds) == -1) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smbd_report("unable to create pipe");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw exit(SMF_EXIT_ERR_FATAL);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw closelog();
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if ((pid = fork()) == -1) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw openlog(smbd.s_pname, LOG_PID | LOG_NOWAIT, LOG_DAEMON);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smbd_report("unable to fork");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw closelog();
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw exit(SMF_EXIT_ERR_FATAL);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
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 */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (pid != 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) close(pfds[1]);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (read(pfds[0], &status, sizeof (status)) == sizeof (status))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw _exit(status);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (waitpid(pid, &status, 0) == pid && WIFEXITED(status))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw _exit(WEXITSTATUS(status));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw _exit(SMF_EXIT_ERR_FATAL);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw openlog(smbd.s_pname, LOG_PID | LOG_NOWAIT, LOG_DAEMON);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) setsid();
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) sigprocmask(SIG_SETMASK, &oset, NULL);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) chdir("/");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) umask(022);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) close(pfds[0]);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (pfds[1]);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright/*
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 Wright */
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightstatic const char root_cp[] = "/core.%f.%t";
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightstatic const char daemon_cp[] = "/var/tmp/core.%f.%t";
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightstatic int
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightsmb_init_daemon_priv(int flags, uid_t uid, gid_t gid)
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright{
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright priv_set_t *perm = NULL;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright int ret = -1;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright char buf[1024];
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright /*
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 */
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if (flags & PU_RESETGROUPS)
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright (void) setgroups(0, NULL);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if (gid != (gid_t)-1 && setgid(gid) != 0)
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright goto end;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright perm = priv_allocset();
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if (perm == NULL)
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright goto end;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright /* E = P */
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright (void) getppriv(PRIV_PERMITTED, perm);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright (void) setppriv(PRIV_SET, PRIV_EFFECTIVE, perm);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright /* Now reset suid and euid */
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if (uid != (uid_t)-1 && setreuid(uid, uid) != 0)
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright goto end;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright /* I = 0 */
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright priv_emptyset(perm);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright ret = setppriv(PRIV_SET, PRIV_INHERITABLE, perm);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightend:
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright priv_freeset(perm);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if (core_get_process_path(buf, sizeof (buf), getpid()) == 0 &&
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright strcmp(buf, "core") == 0) {
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if ((uid == (uid_t)-1 ? geteuid() : uid) == 0) {
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright (void) core_set_process_path(root_cp, sizeof (root_cp),
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright getpid());
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright } else {
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright (void) core_set_process_path(daemon_cp,
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright sizeof (daemon_cp), getpid());
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright }
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright }
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright (void) setpflags(__PROC_PROTECT, 0);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright return (ret);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright}
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright/*
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.
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmbd_daemonize_fini(int fd, int exit_status)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright priv_set_t *pset;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
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.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (fd >= 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) write(fd, &exit_status, sizeof (exit_status));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) close(fd);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright pset = priv_allocset();
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if (pset == NULL)
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright return;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
634e26ec75c89095090605284938356a3145f2b8Casper H.S. Dik priv_basicset(pset);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright /* list of privileges for smbd */
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright (void) priv_addset(pset, PRIV_NET_MAC_AWARE);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright (void) priv_addset(pset, PRIV_NET_PRIVADDR);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright (void) priv_addset(pset, PRIV_PROC_AUDIT);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright (void) priv_addset(pset, PRIV_SYS_DEVICES);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright (void) priv_addset(pset, PRIV_SYS_SMB);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) priv_addset(pset, PRIV_SYS_MOUNT);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright priv_inverse(pset);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright /* turn off unneeded privileges */
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright (void) setppriv(PRIV_OFF, PRIV_EFFECTIVE, pset);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright priv_freeset(pset);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright /* reenable core dumps */
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright __fini_daemon_priv(NULL);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb/*
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * smbd_service_init
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmbd_service_init(void)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
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 },
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross { SMB_VSS, 0755 },
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross { SMB_PIPE_DIR, 0755 },
12b65585e720714b31036daaa2b30eb76014048eGordon Ross { "/var/smb/lipc", 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
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright smbd.s_pid = getpid();
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross /*
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Stop for a debugger attach here, which is after the
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * fork() etc. in smb_daemonize_init()
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross if (smbd.s_dbg_stop) {
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross smbd_report("pid %d stop for debugger attach", smbd.s_pid);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross (void) kill(smbd.s_pid, SIGSTOP);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross }
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross smbd_report("smbd starting, pid %d", smbd.s_pid);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross
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 }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
12b65585e720714b31036daaa2b30eb76014048eGordon Ross /*
12b65585e720714b31036daaa2b30eb76014048eGordon Ross * This environment variable tells mech_krb5 to give us
12b65585e720714b31036daaa2b30eb76014048eGordon Ross * MS-compatible behavior.
12b65585e720714b31036daaa2b30eb76014048eGordon Ross */
12b65585e720714b31036daaa2b30eb76014048eGordon Ross (void) putenv("MS_INTEROP=1");
12b65585e720714b31036daaa2b30eb76014048eGordon Ross
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb if ((rc = smb_ccache_init(SMB_VARRUN_DIR, SMB_CCACHE_FILE)) != 0) {
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb if (rc == -1)
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb smbd_report("mkdir %s: %s", SMB_VARRUN_DIR,
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb strerror(errno));
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb else
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb smbd_report("unable to set KRB5CCNAME");
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States return (-1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross#ifndef FKSMBD
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross /* Upgrade SMF settings, if necessary. */
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross smb_config_upgrade();
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross#endif
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown smb_codepage_init();
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh rc = smbd_cups_init();
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh if (smb_config_getbool(SMB_CI_PRINT_ENABLE))
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smbd_report("print service %savailable", (rc == 0) ? "" : "un");
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if (smbd_nicmon_start(SMBD_DEFAULT_INSTANCE_FMRI) != 0)
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smbd_report("NIC monitor failed to start");
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smbd_dyndns_init();
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright smb_ipc_init();
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
83d2dfe69259e79314662cf95e6d1f9103dcffe2Gordon Ross if (smb_config_getbool(SMB_CI_NETBIOS_ENABLE) == 0)
83d2dfe69259e79314662cf95e6d1f9103dcffe2Gordon Ross smbd_report("NetBIOS services disabled");
83d2dfe69259e79314662cf95e6d1f9103dcffe2Gordon Ross else if (smb_netbios_start() != 0)
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as smbd_report("NetBIOS services failed to start");
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as else
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as smbd_report("NetBIOS services started");
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas smbd.s_secmode = smb_config_get_secmode();
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright if ((rc = smb_domain_init(smbd.s_secmode)) != 0) {
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (rc == SMB_DOMAIN_NOMACHINE_SID) {
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as smbd_report(
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as "no machine SID: check idmap configuration");
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States return (-1);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
1fdeec650620e8498c06f832ea4bd2292f7e9632joyce mcintosh if (smbd_dc_monitor_init() != 0)
1fdeec650620e8498c06f832ea4bd2292f7e9632joyce mcintosh smbd_report("DC monitor initialization failed %s",
1fdeec650620e8498c06f832ea4bd2292f7e9632joyce mcintosh strerror(errno));
1fdeec650620e8498c06f832ea4bd2292f7e9632joyce mcintosh
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross if (smbd_pipesvc_start() != 0) {
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross smbd_report("pipesvc initialization failed");
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States return (-1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
12b65585e720714b31036daaa2b30eb76014048eGordon Ross if (smbd_authsvc_start() != 0) {
12b65585e720714b31036daaa2b30eb76014048eGordon Ross smbd_report("authsvc initialization failed");
12b65585e720714b31036daaa2b30eb76014048eGordon Ross return (-1);
12b65585e720714b31036daaa2b30eb76014048eGordon Ross }
12b65585e720714b31036daaa2b30eb76014048eGordon Ross
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smbd.s_door_srv = smbd_door_start();
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross if (smbd.s_door_srv < 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 }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
8d7e41661dc4633488e93b13363137523ce59977jose borrego dyndns_update_zones();
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smbd_localtime_init();
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as (void) smb_lgrp_start();
3db3f65c6274eb042354801a308c8e9bc4994553amw smb_pwd_init(B_TRUE);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
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);
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
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");
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States
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);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego }
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smbd_load_shares();
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smbd_load_printers();
b7301bf5522d8b9141fe432333ded586218327f2Gordon Ross smbd_spool_start();
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh
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");
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego return (0);
55bf511df53aad0fdb7eb3fa349f0308cc05234cas}
55bf511df53aad0fdb7eb3fa349f0308cc05234cas
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
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.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmbd_service_fini(void)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
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();
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross smbd_pipesvc_stop();
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smbd_door_stop();
12b65585e720714b31036daaa2b30eb76014048eGordon Ross smbd_authsvc_stop();
b7301bf5522d8b9141fe432333ded586218327f2Gordon Ross smbd_spool_stop();
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smbd_kernel_unbind();
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smbd_share_stop();
3db3f65c6274eb042354801a308c8e9bc4994553amw smb_shr_stop();
8d7e41661dc4633488e93b13363137523ce59977jose borrego dyndns_stop();
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smbd_nicmon_stop();
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb smb_ccache_remove(SMB_CCACHE_PATH);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb smb_pwd_fini();
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright smb_domain_fini();
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright mlsvc_fini();
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright smb_netbios_stop();
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smbd_cups_fini();
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
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 closelog();
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
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.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rossstatic void
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rosssmbd_refresh_handler()
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross int new_debug;
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross if (smbd.s_shutting_down)
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross return;
8d7e41661dc4633488e93b13363137523ce59977jose borrego
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross smbd.s_refreshes++;
8d7e41661dc4633488e93b13363137523ce59977jose borrego
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross new_debug = smb_config_get_debug();
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross if (smbd.s_debug || new_debug)
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross smbd_report("debug=%d", new_debug);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross smbd.s_debug = new_debug;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross smbd_spool_stop();
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross smbd_dc_monitor_refresh();
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross smb_ccache_remove(SMB_CCACHE_PATH);
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross /*
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Clear the DNS zones for the existing interfaces
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * before updating the NIC interface list.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross dyndns_clear_zones();
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross if (smbd_nicmon_refresh() != 0)
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross smbd_report("NIC monitor refresh failed");
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross smb_netbios_name_reconfig();
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross smb_browser_reconfig();
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross dyndns_update_zones();
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross /* This reloads the in-kernel config. */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross (void) smbd_kernel_bind();
8d7e41661dc4633488e93b13363137523ce59977jose borrego
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross smbd_load_shares();
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross smbd_load_printers();
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross smbd_spool_start();
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
8d7e41661dc4633488e93b13363137523ce59977jose borregovoid
8d7e41661dc4633488e93b13363137523ce59977jose borregosmbd_set_secmode(int secmode)
8d7e41661dc4633488e93b13363137523ce59977jose borrego{
8d7e41661dc4633488e93b13363137523ce59977jose borrego switch (secmode) {
8d7e41661dc4633488e93b13363137523ce59977jose borrego case SMB_SECMODE_WORKGRP:
8d7e41661dc4633488e93b13363137523ce59977jose borrego case SMB_SECMODE_DOMAIN:
8d7e41661dc4633488e93b13363137523ce59977jose borrego (void) smb_config_set_secmode(secmode);
8d7e41661dc4633488e93b13363137523ce59977jose borrego smbd.s_secmode = secmode;
8d7e41661dc4633488e93b13363137523ce59977jose borrego break;
8d7e41661dc4633488e93b13363137523ce59977jose borrego
8d7e41661dc4633488e93b13363137523ce59977jose borrego default:
8d7e41661dc4633488e93b13363137523ce59977jose borrego syslog(LOG_ERR, "invalid security mode: %d", secmode);
8d7e41661dc4633488e93b13363137523ce59977jose borrego syslog(LOG_ERR, "entering maintenance mode");
8d7e41661dc4633488e93b13363137523ce59977jose borrego (void) smb_smf_maintenance_mode();
8d7e41661dc4633488e93b13363137523ce59977jose borrego }
8d7e41661dc4633488e93b13363137523ce59977jose borrego}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
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/*
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.
1fdeec650620e8498c06f832ea4bd2292f7e9632joyce mcintosh */
1fdeec650620e8498c06f832ea4bd2292f7e9632joyce mcintoshvoid
1fdeec650620e8498c06f832ea4bd2292f7e9632joyce mcintoshsmbd_online_wait(const char *text)
1fdeec650620e8498c06f832ea4bd2292f7e9632joyce mcintosh{
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh while (!smbd_online())
1fdeec650620e8498c06f832ea4bd2292f7e9632joyce mcintosh (void) sleep(SMBD_ONLINE_WAIT_INTERVAL);
1fdeec650620e8498c06f832ea4bd2292f7e9632joyce mcintosh
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh if (text != NULL) {
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross syslog(LOG_DEBUG, "%s: online", text);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh (void) fprintf(stderr, "%s: online\n", text);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh }
1fdeec650620e8498c06f832ea4bd2292f7e9632joyce mcintosh}
1fdeec650620e8498c06f832ea4bd2292f7e9632joyce mcintosh
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
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 */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmbd_already_running(void)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross door_info_t info;
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross char *door_name;
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross int door;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross door_name = getenv("SMBD_DOOR_NAME");
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross if (door_name == NULL)
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross door_name = SMBD_DOOR_NAME;
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross if ((door = open(door_name, O_RDONLY)) < 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (door_info(door, &info) < 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (info.di_target > 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smbd_report("already running: pid %ld\n", info.di_target);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) close(door);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) close(door);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb/*
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * smbd_kernel_bind
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas *
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.
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eassmbd_kernel_bind(void)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smb_kmod_cfg_t cfg;
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh int rc;
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh if (smbd.s_kbound) {
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smb_load_kconfig(&cfg);
12b65585e720714b31036daaa2b30eb76014048eGordon Ross smbd_get_authconf(&cfg);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh rc = smb_kmod_setcfg(&cfg);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh if (rc < 0)
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smbd_report("kernel configuration update failed: %s",
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross strerror(rc));
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh return (rc);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh }
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh if (smb_kmod_isbound())
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smbd_kernel_unbind();
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if ((rc = smb_kmod_bind()) == 0) {
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright rc = smbd_kernel_start();
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if (rc != 0)
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright smb_kmod_unbind();
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright else
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright smbd.s_kbound = B_TRUE;
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross } else {
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross smbd_report("kernel bind error: %s", strerror(rc));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright return (rc);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright}
94fff7907278e4540aa7abee2b1b0ea71d36f7faAlan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightstatic int
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightsmbd_kernel_start(void)
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright{
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright smb_kmod_cfg_t cfg;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright int rc;
8d7e41661dc4633488e93b13363137523ce59977jose borrego
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright smb_load_kconfig(&cfg);
12b65585e720714b31036daaa2b30eb76014048eGordon Ross smbd_get_authconf(&cfg);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright rc = smb_kmod_setcfg(&cfg);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross if (rc != 0) {
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross smbd_report("kernel config ioctl error: %s", strerror(rc));
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright return (rc);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross }
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright rc = smb_kmod_setgmtoff(smbd_gmtoff());
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross if (rc != 0) {
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross smbd_report("kernel gmtoff ioctl error: %s", strerror(rc));
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright return (rc);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross }
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright rc = smb_kmod_start(smbd.s_door_opipe, smbd.s_door_lmshr,
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright smbd.s_door_srv);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross if (rc != 0) {
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross smbd_report("kernel start ioctl error: %s", strerror(rc));
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright return (rc);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross }
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright return (0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb/*
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * smbd_kernel_unbind
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb */
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbstatic void
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbsmbd_kernel_unbind(void)
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb{
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright smb_kmod_unbind();
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright smbd.s_kbound = B_FALSE;
94fff7907278e4540aa7abee2b1b0ea71d36f7faAlan Wright}
94fff7907278e4540aa7abee2b1b0ea71d36f7faAlan Wright
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh/*
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh * Create the Dynamic DNS publisher thread.
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh */
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintoshstatic void
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintoshsmbd_dyndns_init(void)
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh{
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh pthread_t tid;
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh pthread_attr_t attr;
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh int rc;
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh dyndns_start();
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh (void) pthread_attr_init(&attr);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh (void) pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh rc = pthread_create(&tid, &attr, dyndns_publisher, NULL);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh (void) pthread_attr_destroy(&attr);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh if (rc != 0)
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smbd_report("unable to start dyndns publisher: %s",
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh strerror(errno));
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh}
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh/*
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh * Launches a thread to populate the share cache by share information
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh * stored in sharemgr
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh */
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintoshstatic void
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintoshsmbd_load_shares(void)
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh{
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh pthread_t tid;
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh pthread_attr_t attr;
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh int rc;
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh (void) pthread_attr_init(&attr);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh (void) pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross rc = pthread_create(&tid, &attr, smbd_share_loader, NULL);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh (void) pthread_attr_destroy(&attr);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh if (rc != 0)
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smbd_report("unable to load disk shares: %s", strerror(errno));
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh}
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rossstatic void *
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rosssmbd_share_loader(void *args)
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross{
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross (void) smb_shr_load(args);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross return (NULL);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross}
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Initialization of the localtime thread.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Returns 0 on success, an error number if thread creation fails.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintoshstatic void
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmbd_localtime_init(void)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh pthread_attr_t attr;
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh int rc;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh (void) pthread_attr_init(&attr);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh (void) pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh rc = pthread_create(&smbd.s_localtime_tid, &attr,
1fdeec650620e8498c06f832ea4bd2292f7e9632joyce mcintosh smbd_localtime_monitor, NULL);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh (void) pthread_attr_destroy(&attr);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh if (rc != 0)
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smbd_report("unable to monitor localtime: %s", strerror(errno));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
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 */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*ARGSUSED*/
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmbd_localtime_monitor(void *arg)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw struct tm local_tm;
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego time_t secs;
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego int32_t gmtoff, last_gmtoff = -1;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int timeout;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright int error;
94fff7907278e4540aa7abee2b1b0ea71d36f7faAlan Wright
1fdeec650620e8498c06f832ea4bd2292f7e9632joyce mcintosh smbd_online_wait("smbd_localtime_monitor");
1fdeec650620e8498c06f832ea4bd2292f7e9632joyce mcintosh
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw for (;;) {
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego gmtoff = smbd_gmtoff();
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if ((last_gmtoff != gmtoff) && smbd.s_kbound) {
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright error = smb_kmod_setgmtoff(gmtoff);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if (error != 0)
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright smbd_report("localtime set failed: %s",
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright strerror(error));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Align the next iteration on a fifteen minute boundary.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw secs = time(0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) localtime_r(&secs, &local_tm);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw timeout = ((15 - (local_tm.tm_min % 15)) * SECSPERMIN);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) sleep(timeout);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw last_gmtoff = gmtoff;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*NOTREACHED*/
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (NULL);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego/*
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * smbd_gmtoff
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego *
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * Determine offset from GMT. If daylight saving time use altzone,
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * otherwise use timezone.
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego */
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borregostatic int32_t
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borregosmbd_gmtoff(void)
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego{
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego time_t clock_val;
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego struct tm *atm;
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego int32_t gmtoff;
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego (void) time(&clock_val);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego atm = localtime(&clock_val);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego gmtoff = (atm->tm_isdst) ? altzone : timezone;
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego return (gmtoff);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego}
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
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 *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Failure to find a uid or gid results in using the default (0).
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmbd_setup_options(int argc, char *argv[])
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw struct passwd *pwd;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw struct group *grp;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int c;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if ((pwd = getpwnam("root")) != NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smbd.s_uid = pwd->pw_uid;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if ((grp = getgrnam("sys")) != NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smbd.s_gid = grp->gr_gid;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross smbd.s_debug = smb_config_get_debug();
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as smbd.s_fg = smb_config_get_fg_flag();
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross while ((c = getopt(argc, argv, ":dfs")) != -1) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw switch (c) {
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross case 'd':
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross smbd.s_debug++;
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross break;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case 'f':
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smbd.s_fg = 1;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw break;
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross case 's':
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross smbd.s_dbg_stop = 1;
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross break;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case ':':
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case '?':
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw default:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smbd_usage(stderr);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (-1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmbd_usage(FILE *fp)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw static char *help[] = {
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross "-d enable debug messages"
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw "-f run program in foreground"
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw };
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int i;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) fprintf(fp, "Usage: %s [-f]\n", smbd.s_pname);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw for (i = 0; i < sizeof (help)/sizeof (help[0]); ++i)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) fprintf(fp, " %s\n", help[i]);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rossvoid
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmbd_report(const char *fmt, ...)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char buf[128];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw va_list ap;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (fmt == NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw va_start(ap, fmt);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) vsnprintf(buf, 128, fmt, ap);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw va_end(ap);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) fprintf(stderr, "smbd: %s\n", buf);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Enable libumem debugging by default on DEBUG builds.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#ifdef DEBUG
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwconst char *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw_umem_debug_init(void)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return ("default,verbose"); /* $UMEM_DEBUG setting */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwconst char *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw_umem_logging_init(void)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return ("fail,contents"); /* $UMEM_LOGGING setting */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#endif