usr/src/lib/smbsrv/libsmb/common/smb_info.c
author natalie li - Sun Microsystems - Irvine United States <Natalie.Li@Sun.COM>
Tue, 28 Oct 2008 03:34:04 -0700
changeset 7961 4b5e3051f38b
parent 7348 73b61202d5d6
child 8334 5f1c6a3b0fad
permissions -rw-r--r--
6751647 TRANS2_FIND_NEXT continuation by filename restarts search at beginning of directory 6753904 SVCCTL server side service 6741484 Local users cannot connect to CIFS shares from MacOS 10.5 6746898 win98 can not overwrite *.files 6753310 Incorrect handling of SmbNegotiate request when invalid dialects are negotiated. 6751123 Unable to join domain, core dump generated with IPMP setting 6722437 SMB_TRANS2_FIND returns wrong status code when stream file is passed 6716578 can not delete file in extended attribute name space in cifs client when cifs server is solaris PSARC 2008/584 Correction in nbmand behavior 6734067 Long delay when viewing MS Word Read-only file properties with nbmand enabled. PSARC/2007/281 NFS share properties for Montana compatibility 6475452 Need Solaris support for Montana approve file functionality in NFS 6582170 Host-based access control (approve file) 6749075 Unable to join domain if user password exceeds 20 characters 6612716 Join domain fails if hostname is > 15 chars 6753251 server signing: wrong signature is generated for the NetShareEnum reply 6757521 SMB daemon leaks memory after displaying GSS status 6760315 Local user cannot connnect to CIFS shares if CIFS server's hostname is not specified 6757333 Share publisher thread runs into infinite loop of displaying GSS major/minor status 6757132 smbd crashes at smb_idmap_batch_getmappings 6760876 security descriptor decoding function has a glitch 6761491 Cannot open or delete a named stream on a directory file. 6741449 Cleanup list in smbns_ads module 6593958 Users with restore privilege can take ownership of files
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
#include <sys/types.h>
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    27
#include <stdarg.h>
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    28
#include <unistd.h>
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    29
#include <stdlib.h>
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    30
#include <time.h>
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    31
#include <synch.h>
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    32
#include <syslog.h>
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    33
#include <string.h>
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    34
#include <strings.h>
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    35
#include <errno.h>
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    36
#include <net/if.h>
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    37
#include <netdb.h>
5772
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
    38
#include <netinet/in.h>
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
    39
#include <arpa/nameser.h>
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
    40
#include <resolv.h>
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    41
#include <sys/sockio.h>
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    42
#include <smbsrv/smbinfo.h>
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    43
#include <smbsrv/netbios.h>
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    44
#include <smbsrv/libsmb.h>
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    45
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    46
static smb_ntdomain_t smbpdc_cache;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    47
static mutex_t smbpdc_mtx;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    48
static cond_t smbpdc_cv;
6139
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
    49
static mutex_t seqnum_mtx;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    50
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    51
extern int getdomainname(char *, int);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    52
5521
cf62335046cd 6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents: 5331
diff changeset
    53
/*
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    54
 * smb_getdomaininfo
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    55
 *
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    56
 * Returns a pointer to the cached domain data. The caller can specify
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    57
 * whether or not he is prepared to wait if the cache is not yet valid
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    58
 * and for how long. The specified timeout is in seconds.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    59
 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    60
smb_ntdomain_t *
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    61
smb_getdomaininfo(uint32_t timeout)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    62
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    63
	timestruc_t to;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    64
	int err;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    65
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    66
	if (timeout != 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    67
		(void) mutex_lock(&smbpdc_mtx);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    68
		while (smbpdc_cache.ipaddr == 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    69
			to.tv_sec = timeout;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    70
			to.tv_nsec = 0;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    71
			err = cond_reltimedwait(&smbpdc_cv, &smbpdc_mtx, &to);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    72
			if (err == ETIME)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    73
				break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    74
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    75
		(void) mutex_unlock(&smbpdc_mtx);
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
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    78
	if (smbpdc_cache.ipaddr != 0)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    79
		return (&smbpdc_cache);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    80
	else
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    81
		return (0);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    82
}
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
void
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    85
smb_logdomaininfo(smb_ntdomain_t *di)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    86
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    87
	char ipstr[16];
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
	(void) inet_ntop(AF_INET, (const void *)&di->ipaddr, ipstr,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    90
	    sizeof (ipstr));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    91
	syslog(LOG_DEBUG, "smbd: %s (%s:%s)", di->domain, di->server, ipstr);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    92
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    93
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    94
/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    95
 * smb_setdomaininfo
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    96
 *
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    97
 * Set the information for the specified domain. If the information is
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    98
 * non-null, the notification event is raised to wakeup any threads
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
    99
 * blocking on the cache.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   100
 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   101
void
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   102
smb_setdomaininfo(char *domain, char *server, uint32_t ipaddr)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   103
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   104
	char *p;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   105
7348
73b61202d5d6 6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents: 6600
diff changeset
   106
	(void) mutex_lock(&smbpdc_mtx);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   107
	bzero(&smbpdc_cache, sizeof (smb_ntdomain_t));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   108
	if (domain && server && ipaddr) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   109
		(void) strlcpy(smbpdc_cache.domain, domain, SMB_PI_MAX_DOMAIN);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   110
		(void) strlcpy(smbpdc_cache.server, server, SMB_PI_MAX_DOMAIN);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   111
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   112
		/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   113
		 * Remove DNS domain name extension
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   114
		 * to avoid confusing NetBIOS.
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
		if ((p = strchr(smbpdc_cache.domain, '.')) != 0)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   117
			*p = '\0';
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 ((p = strchr(smbpdc_cache.server, '.')) != 0)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   120
			*p = '\0';
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
		smbpdc_cache.ipaddr = ipaddr;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   123
		(void) cond_broadcast(&smbpdc_cv);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   124
	}
7348
73b61202d5d6 6584155 Confusing 'No such object' message is logged when a share is successfully published.
jose borrego <Jose.Borrego@Sun.COM>
parents: 6600
diff changeset
   125
	(void) mutex_unlock(&smbpdc_mtx);
5331
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
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   128
void
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   129
smb_load_kconfig(smb_kmod_cfg_t *kcfg)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   130
{
5772
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   131
	int64_t citem;
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   132
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   133
	bzero(kcfg, sizeof (smb_kmod_cfg_t));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   134
5772
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   135
	(void) smb_config_getnum(SMB_CI_MAX_WORKERS, &citem);
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   136
	kcfg->skc_maxworkers = (uint32_t)citem;
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   137
	(void) smb_config_getnum(SMB_CI_KEEPALIVE, &citem);
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   138
	kcfg->skc_keepalive = (uint32_t)citem;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   139
	if ((kcfg->skc_keepalive != 0) &&
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   140
	    (kcfg->skc_keepalive < SMB_PI_KEEP_ALIVE_MIN))
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   141
		kcfg->skc_keepalive = SMB_PI_KEEP_ALIVE_MIN;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   142
5772
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   143
	(void) smb_config_getnum(SMB_CI_MAX_CONNECTIONS, &citem);
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   144
	kcfg->skc_maxconnections = (uint32_t)citem;
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   145
	kcfg->skc_restrict_anon = smb_config_getbool(SMB_CI_RESTRICT_ANON);
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   146
	kcfg->skc_signing_enable = smb_config_getbool(SMB_CI_SIGNING_ENABLE);
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   147
	kcfg->skc_signing_required = smb_config_getbool(SMB_CI_SIGNING_REQD);
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   148
	kcfg->skc_oplock_enable = smb_config_getbool(SMB_CI_OPLOCK_ENABLE);
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   149
	kcfg->skc_sync_enable = smb_config_getbool(SMB_CI_SYNC_ENABLE);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   150
	kcfg->skc_secmode = smb_config_get_secmode();
7961
4b5e3051f38b 6751647 TRANS2_FIND_NEXT continuation by filename restarts search at beginning of directory
natalie li - Sun Microsystems - Irvine United States <Natalie.Li@Sun.COM>
parents: 7348
diff changeset
   151
	(void) smb_getdomainname(kcfg->skc_nbdomain,
4b5e3051f38b 6751647 TRANS2_FIND_NEXT continuation by filename restarts search at beginning of directory
natalie li - Sun Microsystems - Irvine United States <Natalie.Li@Sun.COM>
parents: 7348
diff changeset
   152
	    sizeof (kcfg->skc_nbdomain));
4b5e3051f38b 6751647 TRANS2_FIND_NEXT continuation by filename restarts search at beginning of directory
natalie li - Sun Microsystems - Irvine United States <Natalie.Li@Sun.COM>
parents: 7348
diff changeset
   153
	(void) smb_getfqdomainname(kcfg->skc_fqdn,
4b5e3051f38b 6751647 TRANS2_FIND_NEXT continuation by filename restarts search at beginning of directory
natalie li - Sun Microsystems - Irvine United States <Natalie.Li@Sun.COM>
parents: 7348
diff changeset
   154
	    sizeof (kcfg->skc_fqdn));
4b5e3051f38b 6751647 TRANS2_FIND_NEXT continuation by filename restarts search at beginning of directory
natalie li - Sun Microsystems - Irvine United States <Natalie.Li@Sun.COM>
parents: 7348
diff changeset
   155
	(void) smb_getnetbiosname(kcfg->skc_hostname,
4b5e3051f38b 6751647 TRANS2_FIND_NEXT continuation by filename restarts search at beginning of directory
natalie li - Sun Microsystems - Irvine United States <Natalie.Li@Sun.COM>
parents: 7348
diff changeset
   156
	    sizeof (kcfg->skc_hostname));
5772
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   157
	(void) smb_config_getstr(SMB_CI_SYS_CMNT, kcfg->skc_system_comment,
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   158
	    sizeof (kcfg->skc_system_comment));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   159
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   160
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
 * Get the current system NetBIOS name.  The hostname is truncated at
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   163
 * the first `.` or 15 bytes, whichever occurs first, and converted
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   164
 * to uppercase (by smb_gethostname).  Text that appears after the
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   165
 * first '.' is considered to be part of the NetBIOS scope.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   166
 *
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   167
 * Returns 0 on success, otherwise -1 to indicate an error.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   168
 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   169
int
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   170
smb_getnetbiosname(char *buf, size_t buflen)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   171
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   172
	if (smb_gethostname(buf, buflen, 1) != 0)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   173
		return (-1);
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 (buflen >= NETBIOS_NAME_SZ)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   176
		buf[NETBIOS_NAME_SZ - 1] = '\0';
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   177
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   178
	return (0);
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
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   181
/*
7961
4b5e3051f38b 6751647 TRANS2_FIND_NEXT continuation by filename restarts search at beginning of directory
natalie li - Sun Microsystems - Irvine United States <Natalie.Li@Sun.COM>
parents: 7348
diff changeset
   182
 * Get the SAM account of the current system.
4b5e3051f38b 6751647 TRANS2_FIND_NEXT continuation by filename restarts search at beginning of directory
natalie li - Sun Microsystems - Irvine United States <Natalie.Li@Sun.COM>
parents: 7348
diff changeset
   183
 * Returns 0 on success, otherwise, -1 to indicate an error.
4b5e3051f38b 6751647 TRANS2_FIND_NEXT continuation by filename restarts search at beginning of directory
natalie li - Sun Microsystems - Irvine United States <Natalie.Li@Sun.COM>
parents: 7348
diff changeset
   184
 */
4b5e3051f38b 6751647 TRANS2_FIND_NEXT continuation by filename restarts search at beginning of directory
natalie li - Sun Microsystems - Irvine United States <Natalie.Li@Sun.COM>
parents: 7348
diff changeset
   185
int
4b5e3051f38b 6751647 TRANS2_FIND_NEXT continuation by filename restarts search at beginning of directory
natalie li - Sun Microsystems - Irvine United States <Natalie.Li@Sun.COM>
parents: 7348
diff changeset
   186
smb_getsamaccount(char *buf, size_t buflen)
4b5e3051f38b 6751647 TRANS2_FIND_NEXT continuation by filename restarts search at beginning of directory
natalie li - Sun Microsystems - Irvine United States <Natalie.Li@Sun.COM>
parents: 7348
diff changeset
   187
{
4b5e3051f38b 6751647 TRANS2_FIND_NEXT continuation by filename restarts search at beginning of directory
natalie li - Sun Microsystems - Irvine United States <Natalie.Li@Sun.COM>
parents: 7348
diff changeset
   188
	if (smb_getnetbiosname(buf, buflen - 1) != 0)
4b5e3051f38b 6751647 TRANS2_FIND_NEXT continuation by filename restarts search at beginning of directory
natalie li - Sun Microsystems - Irvine United States <Natalie.Li@Sun.COM>
parents: 7348
diff changeset
   189
		return (-1);
4b5e3051f38b 6751647 TRANS2_FIND_NEXT continuation by filename restarts search at beginning of directory
natalie li - Sun Microsystems - Irvine United States <Natalie.Li@Sun.COM>
parents: 7348
diff changeset
   190
4b5e3051f38b 6751647 TRANS2_FIND_NEXT continuation by filename restarts search at beginning of directory
natalie li - Sun Microsystems - Irvine United States <Natalie.Li@Sun.COM>
parents: 7348
diff changeset
   191
	(void) strlcat(buf, "$", buflen);
4b5e3051f38b 6751647 TRANS2_FIND_NEXT continuation by filename restarts search at beginning of directory
natalie li - Sun Microsystems - Irvine United States <Natalie.Li@Sun.COM>
parents: 7348
diff changeset
   192
	return (0);
4b5e3051f38b 6751647 TRANS2_FIND_NEXT continuation by filename restarts search at beginning of directory
natalie li - Sun Microsystems - Irvine United States <Natalie.Li@Sun.COM>
parents: 7348
diff changeset
   193
}
4b5e3051f38b 6751647 TRANS2_FIND_NEXT continuation by filename restarts search at beginning of directory
natalie li - Sun Microsystems - Irvine United States <Natalie.Li@Sun.COM>
parents: 7348
diff changeset
   194
4b5e3051f38b 6751647 TRANS2_FIND_NEXT continuation by filename restarts search at beginning of directory
natalie li - Sun Microsystems - Irvine United States <Natalie.Li@Sun.COM>
parents: 7348
diff changeset
   195
/*
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   196
 * Get the current system node name.  The returned name is guaranteed
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   197
 * to be null-terminated (gethostname may not null terminate the name).
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   198
 * If the hostname has been fully-qualified for some reason, the domain
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   199
 * part will be removed.  If the caller would like the name in upper
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   200
 * case, it is folded to uppercase.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   201
 *
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   202
 * If gethostname fails, the returned buffer will contain an empty
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   203
 * string.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   204
 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   205
int
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   206
smb_gethostname(char *buf, size_t buflen, int upcase)
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
	char *p;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   209
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   210
	if (buf == NULL || buflen == 0)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   211
		return (-1);
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
	if (gethostname(buf, buflen) != 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   214
		*buf = '\0';
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   215
		return (-1);
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
	buf[buflen - 1] = '\0';
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   219
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   220
	if ((p = strchr(buf, '.')) != NULL)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   221
		*p = '\0';
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   222
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   223
	if (upcase)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   224
		(void) utf8_strupr(buf);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   225
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   226
	return (0);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   227
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   228
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   229
/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   230
 * Obtain the fully-qualified name for this machine.  If the
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   231
 * hostname is fully-qualified, accept it.  Otherwise, try to
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   232
 * find an appropriate domain name to append to the hostname.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   233
 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   234
int
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   235
smb_getfqhostname(char *buf, size_t buflen)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   236
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   237
	char hostname[MAXHOSTNAMELEN];
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   238
	char domain[MAXHOSTNAMELEN];
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   239
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   240
	hostname[0] = '\0';
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   241
	domain[0] = '\0';
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   242
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   243
	if (smb_gethostname(hostname, MAXHOSTNAMELEN, 0) != 0)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   244
		return (-1);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   245
5772
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   246
	if (smb_getfqdomainname(domain, MAXHOSTNAMELEN) != 0)
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   247
		return (-1);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   248
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   249
	if (hostname[0] == '\0')
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   250
		return (-1);
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
	if (domain[0] == '\0') {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   253
		(void) strlcpy(buf, hostname, buflen);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   254
		return (0);
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
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   257
	(void) snprintf(buf, buflen, "%s.%s", hostname, domain);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   258
	return (0);
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
/*
5772
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   262
 * smb_resolve_netbiosname
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   263
 *
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   264
 * Convert the fully-qualified domain name (i.e. fqdn) to a NETBIOS name.
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   265
 * Upon success, the NETBIOS name will be returned via buf parameter.
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   266
 * Returns 0 upon success.  Otherwise, returns -1.
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   267
 */
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   268
int
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   269
smb_resolve_netbiosname(char *fqdn, char *buf, size_t buflen)
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   270
{
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   271
	char *p;
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   272
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   273
	if (!buf)
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   274
		return (-1);
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   275
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   276
	*buf = '\0';
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   277
	if (!fqdn)
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   278
		return (-1);
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   279
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   280
	(void) strlcpy(buf, fqdn, buflen);
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   281
	if ((p = strchr(buf, '.')) != NULL)
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   282
		*p = 0;
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   283
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   284
	if (strlen(buf) >= NETBIOS_NAME_SZ)
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   285
		buf[NETBIOS_NAME_SZ - 1] = '\0';
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   286
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   287
	return (0);
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   288
}
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   289
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   290
/*
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   291
 * smb_getdomainname
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   292
 *
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   293
 * Returns NETBIOS name of the domain if the system is in domain
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   294
 * mode. Or returns workgroup name if the system is in workgroup
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   295
 * mode.
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   296
 */
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   297
int
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   298
smb_getdomainname(char *buf, size_t buflen)
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   299
{
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   300
	char domain[MAXHOSTNAMELEN];
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   301
	int rc;
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   302
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   303
	if (buf == NULL || buflen == 0)
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   304
		return (-1);
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   305
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   306
	*buf = '\0';
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   307
	rc = smb_config_getstr(SMB_CI_DOMAIN_NAME, domain,
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   308
	    sizeof (domain));
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   309
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   310
	if ((rc != SMBD_SMF_OK) || (*domain == '\0'))
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   311
		return (-1);
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   312
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   313
	(void) smb_resolve_netbiosname(domain, buf, buflen);
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   314
	return (0);
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   315
}
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   316
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   317
/*
6139
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   318
 * smb_getdomainsid
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   319
 *
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   320
 * Returns the domain SID if the system is in domain mode.
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   321
 * Otherwise returns NULL.
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   322
 *
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   323
 * Note: Callers are responsible for freeing a returned SID.
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   324
 */
6432
98715880dd9e 6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents: 6139
diff changeset
   325
smb_sid_t *
6139
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   326
smb_getdomainsid(void)
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   327
{
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   328
	char buf[MAXHOSTNAMELEN];
6432
98715880dd9e 6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents: 6139
diff changeset
   329
	smb_sid_t *sid;
6139
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   330
	int security_mode;
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   331
	int rc;
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   332
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   333
	security_mode = smb_config_get_secmode();
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   334
	if (security_mode != SMB_SECMODE_DOMAIN)
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   335
		return (NULL);
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   336
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   337
	*buf = '\0';
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   338
	rc = smb_config_getstr(SMB_CI_DOMAIN_SID, buf, MAXHOSTNAMELEN);
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   339
	if ((rc != SMBD_SMF_OK) || (*buf == '\0'))
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   340
		return (NULL);
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   341
6432
98715880dd9e 6666802 Cannot copy >1023 byte readonly file from Vista client to Solaris CIFS share
as200622
parents: 6139
diff changeset
   342
	if ((sid = smb_sid_fromstr(buf)) == NULL)
6139
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   343
		return (NULL);
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   344
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   345
	return (sid);
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   346
}
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   347
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   348
/*
5772
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   349
 * smb_resolve_fqdn
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   350
 *
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   351
 * Converts the NETBIOS name of the domain (i.e. nbt_domain) to a fully
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   352
 * qualified domain name. The domain from either the domain field or
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   353
 * search list field of the /etc/resolv.conf will be returned via the
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   354
 * buf parameter if the first label of the domain matches the given
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   355
 * NETBIOS name.
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   356
 *
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   357
 * Returns -1 upon error. If a match is found, returns 1. Otherwise,
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   358
 * returns 0.
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   359
 */
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   360
int
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   361
smb_resolve_fqdn(char *nbt_domain, char *buf, size_t buflen)
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   362
{
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   363
	struct __res_state res_state;
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   364
	int i, found = 0;
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   365
	char *p;
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   366
	int dlen;
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   367
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   368
	if (!buf)
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   369
		return (-1);
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   370
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   371
	*buf = '\0';
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   372
	if (!nbt_domain)
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   373
		return (-1);
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   374
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   375
	bzero(&res_state, sizeof (struct __res_state));
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   376
	if (res_ninit(&res_state))
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   377
		return (-1);
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   378
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   379
	if (*nbt_domain == '\0') {
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   380
		if (*res_state.defdname == '\0') {
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   381
			res_ndestroy(&res_state);
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   382
			return (0);
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   383
		}
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   384
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   385
		(void) strlcpy(buf, res_state.defdname, buflen);
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   386
		res_ndestroy(&res_state);
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   387
		return (1);
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   388
	}
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   389
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   390
	dlen = strlen(nbt_domain);
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   391
	if (!strncasecmp(nbt_domain, res_state.defdname, dlen)) {
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   392
		(void) strlcpy(buf, res_state.defdname, buflen);
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   393
		res_ndestroy(&res_state);
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   394
		return (1);
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   395
	}
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   396
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   397
	for (i = 0; (p = res_state.dnsrch[i]) != NULL; i++) {
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   398
		if (!strncasecmp(nbt_domain, p, dlen)) {
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   399
			(void) strlcpy(buf, p, buflen);
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   400
			found = 1;
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   401
			break;
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   402
		}
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   403
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   404
	}
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   405
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   406
	res_ndestroy(&res_state);
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   407
	return (found);
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   408
}
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   409
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   410
/*
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   411
 * smb_getfqdomainname
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   412
 *
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   413
 * If the domain_name property value is FQDN, it will be returned.
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   414
 * In domain mode, the domain from either the domain field or
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   415
 * search list field of the /etc/resolv.conf will be returned via the
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   416
 * buf parameter if the first label of the domain matches the
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   417
 * domain_name property. In workgroup mode, it returns the local
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   418
 * domain.
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   419
 *
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   420
 * Returns 0 upon success.  Otherwise, returns -1.
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   421
 */
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   422
int
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   423
smb_getfqdomainname(char *buf, size_t buflen)
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   424
{
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   425
	char domain[MAXHOSTNAMELEN];
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   426
	int rc = 0;
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   427
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   428
	if (buf == NULL || buflen == 0)
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   429
		return (-1);
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   430
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   431
	*buf = '\0';
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   432
	if (smb_config_get_secmode() == SMB_SECMODE_DOMAIN) {
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   433
		rc = smb_config_getstr(SMB_CI_DOMAIN_NAME, domain,
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   434
		    sizeof (domain));
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   435
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   436
		if ((rc != SMBD_SMF_OK) || (*domain == '\0'))
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   437
			return (-1);
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   438
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   439
		if (strchr(domain, '.') == NULL) {
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   440
			if (smb_resolve_fqdn(domain, buf, buflen) != 1)
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   441
				rc = -1;
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   442
		} else {
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   443
			(void) strlcpy(buf, domain, buflen);
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   444
		}
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   445
	} else {
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   446
		if (smb_resolve_fqdn("", buf, buflen) != 1)
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   447
			rc = -1;
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   448
	}
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   449
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   450
	return (rc);
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   451
}
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   452
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   453
6139
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   454
/*
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   455
 * smb_set_machine_passwd
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   456
 *
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   457
 * This function should be used when setting the machine password property.
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   458
 * The associated sequence number is incremented.
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   459
 */
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   460
static int
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   461
smb_set_machine_passwd(char *passwd)
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   462
{
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   463
	int64_t num;
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   464
	int rc = -1;
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   465
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   466
	if (smb_config_set(SMB_CI_MACHINE_PASSWD, passwd) != SMBD_SMF_OK)
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   467
		return (-1);
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   468
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   469
	(void) mutex_lock(&seqnum_mtx);
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   470
	(void) smb_config_getnum(SMB_CI_KPASSWD_SEQNUM, &num);
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   471
	if (smb_config_setnum(SMB_CI_KPASSWD_SEQNUM, ++num)
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   472
	    == SMBD_SMF_OK)
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   473
		rc = 0;
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   474
	(void) mutex_unlock(&seqnum_mtx);
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   475
	return (rc);
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   476
}
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   477
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   478
/*
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   479
 * smb_match_netlogon_seqnum
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   480
 *
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   481
 * A sequence number is associated with each machine password property
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   482
 * update and the netlogon credential chain setup. If the
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   483
 * sequence numbers don't match, a NETLOGON credential chain
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   484
 * establishment is required.
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   485
 *
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   486
 * Returns 0 if kpasswd_seqnum equals to netlogon_seqnum. Otherwise,
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   487
 * returns -1.
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   488
 */
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   489
boolean_t
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   490
smb_match_netlogon_seqnum(void)
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   491
{
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   492
	int64_t setpasswd_seqnum;
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   493
	int64_t netlogon_seqnum;
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   494
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   495
	(void) mutex_lock(&seqnum_mtx);
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   496
	(void) smb_config_getnum(SMB_CI_KPASSWD_SEQNUM, &setpasswd_seqnum);
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   497
	(void) smb_config_getnum(SMB_CI_NETLOGON_SEQNUM, &netlogon_seqnum);
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   498
	(void) mutex_unlock(&seqnum_mtx);
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   499
	return (setpasswd_seqnum == netlogon_seqnum);
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   500
}
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   501
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   502
/*
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   503
 * smb_setdomainprops
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   504
 *
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   505
 * This function should be called after joining an AD to
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   506
 * set all the domain related SMF properties.
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   507
 *
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   508
 * The kpasswd_domain property is the AD domain to which the system
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   509
 * is joined via kclient. If this function is invoked by the SMB
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   510
 * daemon, fqdn should be set to NULL.
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   511
 */
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   512
int
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   513
smb_setdomainprops(char *fqdn, char *server, char *passwd)
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   514
{
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   515
	if (server == NULL || passwd == NULL)
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   516
		return (-1);
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   517
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   518
	if ((*server == '\0') || (*passwd == '\0'))
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   519
		return (-1);
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   520
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   521
	if (fqdn && (smb_config_set(SMB_CI_KPASSWD_DOMAIN, fqdn) != 0))
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   522
		return (-1);
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   523
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   524
	if (smb_config_set(SMB_CI_KPASSWD_SRV, server) != 0)
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   525
		return (-1);
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   526
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   527
	if (smb_set_machine_passwd(passwd) != 0) {
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   528
		syslog(LOG_ERR, "smb_setdomainprops: failed to set"
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   529
		    " machine account password");
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   530
		return (-1);
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   531
	}
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   532
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   533
	/*
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   534
	 * If we successfully create a trust account, we mark
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   535
	 * ourselves as a domain member in the environment so
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   536
	 * that we use the SAMLOGON version of the NETLOGON
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   537
	 * PDC location protocol.
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   538
	 */
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   539
	(void) smb_config_setbool(SMB_CI_DOMAIN_MEMB, B_TRUE);
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   540
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   541
	return (0);
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   542
}
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   543
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   544
/*
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   545
 * smb_update_netlogon_seqnum
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   546
 *
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   547
 * This function should only be called upon a successful netlogon
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   548
 * credential chain establishment to set the sequence number of the
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   549
 * netlogon to match with that of the kpasswd.
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   550
 */
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   551
void
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   552
smb_update_netlogon_seqnum(void)
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   553
{
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   554
	int64_t num;
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   555
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   556
	(void) mutex_lock(&seqnum_mtx);
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   557
	(void) smb_config_getnum(SMB_CI_KPASSWD_SEQNUM, &num);
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   558
	(void) smb_config_setnum(SMB_CI_NETLOGON_SEQNUM, num);
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   559
	(void) mutex_unlock(&seqnum_mtx);
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   560
}
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6030
diff changeset
   561
5772
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   562
237ac22142fe 6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents: 5521
diff changeset
   563
/*
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   564
 * Temporary fbt for dtrace until user space sdt enabled.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   565
 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   566
void
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   567
smb_tracef(const char *fmt, ...)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   568
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   569
	va_list ap;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   570
	char buf[128];
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   571
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   572
	va_start(ap, fmt);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   573
	(void) vsnprintf(buf, 128, fmt, ap);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   574
	va_end(ap);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   575
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   576
	smb_trace(buf);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   577
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   578
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   579
/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   580
 * Temporary fbt for dtrace until user space sdt enabled.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   581
 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   582
void
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   583
smb_trace(const char *s)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   584
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   585
	syslog(LOG_DEBUG, "%s", s);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents:
diff changeset
   586
}
6030
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   587
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   588
/*
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   589
 * smb_tonetbiosname
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   590
 *
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   591
 * Creates a NetBIOS name based on the given name and suffix.
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   592
 * NetBIOS name is 15 capital characters, padded with space if needed
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   593
 * and the 16th byte is the suffix.
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   594
 */
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   595
void
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   596
smb_tonetbiosname(char *name, char *nb_name, char suffix)
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   597
{
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   598
	char tmp_name[NETBIOS_NAME_SZ];
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   599
	mts_wchar_t wtmp_name[NETBIOS_NAME_SZ];
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   600
	unsigned int cpid;
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   601
	int len;
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   602
	size_t rc;
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   603
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   604
	len = 0;
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   605
	rc = mts_mbstowcs(wtmp_name, (const char *)name, NETBIOS_NAME_SZ);
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   606
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   607
	if (rc != (size_t)-1) {
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   608
		wtmp_name[NETBIOS_NAME_SZ - 1] = 0;
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   609
		cpid = oem_get_smb_cpid();
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   610
		rc = unicodestooems(tmp_name, wtmp_name, NETBIOS_NAME_SZ, cpid);
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   611
		if (rc > 0)
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   612
			len = strlen(tmp_name);
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   613
	}
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   614
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   615
	(void) memset(nb_name, ' ', NETBIOS_NAME_SZ - 1);
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   616
	if (len) {
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   617
		(void) utf8_strupr(tmp_name);
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   618
		(void) memcpy(nb_name, tmp_name, len);
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   619
	}
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   620
	nb_name[NETBIOS_NAME_SZ - 1] = suffix;
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   621
}
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   622
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   623
int
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   624
smb_get_nameservers(struct in_addr *ips, int sz)
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   625
{
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   626
	union res_sockaddr_union set[MAXNS];
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   627
	int i, cnt;
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   628
	struct __res_state res_state;
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   629
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   630
	if (ips == NULL)
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   631
		return (0);
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   632
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   633
	bzero(&res_state, sizeof (struct __res_state));
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   634
	if (res_ninit(&res_state) < 0)
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   635
		return (0);
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   636
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   637
	cnt = res_getservers(&res_state, set, MAXNS);
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   638
	for (i = 0; i < cnt; i++) {
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   639
		if (i >= sz)
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   640
			break;
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   641
		ips[i] = set[i].sin.sin_addr;
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   642
		syslog(LOG_DEBUG, "NS Found %s name server\n",
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   643
		    inet_ntoa(ips[i]));
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   644
	}
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   645
	syslog(LOG_DEBUG, "NS Found %d name servers\n", i);
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   646
	res_ndestroy(&res_state);
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   647
	return (i);
6bebab7d43d5 6653315 Want smb interface to associate hostname with network interfaces
jb150015
parents: 5772
diff changeset
   648
}