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