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