da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER START
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The contents of this file are subject to the terms of the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Common Development and Distribution License (the "License").
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * You may not use this file except in compliance with the License.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * See the License for the specific language governing permissions
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * and limitations under the License.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * When distributing Covered Code, include this CDDL HEADER in each
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If applicable, add the following below this CDDL HEADER, with the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * fields enclosed by brackets "[]" replaced with your own identifying
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * information: Portions Copyright [yyyy] [name of copyright owner]
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER END
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States#include <tiuser.h>
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States#include <netconfig.h>
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States#include <netdir.h>
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States#include <sys/systeminfo.h>
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States#include <sys/utsname.h>
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown#define SMB_LIB_ALT "/usr/lib/smbsrv/libsmbex.so"
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United Statesstatic boolean_t smb_netgroup_match(struct nd_hostservlist *, char *, int);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United Statesextern int __netdir_getbyaddr_nosrv(struct netconfig *,
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States struct nd_hostservlist **, struct netbuf *);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define H2C(c) (((c) >= '0' && (c) <= '9') ? ((c) - '0') : \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Simple hex dump display function. Displays nbytes of buffer in hex and
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * printable format. Non-printing characters are shown as '.'. It is safe
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * to pass a null pointer. Each line begins with the offset. If nbytes is
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 0, the line will be blank except for the offset. Example output:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 00000000 54 68 69 73 20 69 73 20 61 20 70 72 6F 67 72 61 This is a progra
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 00000010 6D 20 74 65 73 74 2E 00 m test..
dc20a3024900c47dd2ee44b9707e6df38f7d62a5ashexdump_offset(unsigned char *buffer, int nbytes, unsigned long *start)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned char *p;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw for (i = 0; i < nbytes; ++i) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (i && (i % 16) == 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * bintohex
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Converts the given binary data (srcbuf) to
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * its equivalent hex chars (hexbuf).
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * hexlen should be at least twice as srclen.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * if hexbuf is not big enough returns 0.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * otherwise returns number of valid chars in
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * hexbuf which is srclen * 2.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw while (srclen-- > 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * hextobin
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Converts hex to binary.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Assuming hexbuf only contains hex digits (chars)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * this function convert every two bytes of hexbuf
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * to one byte and put it in dstbuf.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * hexlen should be an even number.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * dstlen should be at least half of hexlen.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Returns 0 if sizes are not correct, otherwise
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * returns the number of converted bytes in dstbuf
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * which is half of hexlen.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw while (hexlen > 0) {
8d7e41661dc4633488e93b13363137523ce59977jose borrego * Trim leading and trailing characters in the set defined by class
8d7e41661dc4633488e93b13363137523ce59977jose borrego * from a buffer containing a null-terminated string.
8d7e41661dc4633488e93b13363137523ce59977jose borrego * For example, if the input buffer contained "ABtext23" and class
8d7e41661dc4633488e93b13363137523ce59977jose borrego * contains "ABC123", the buffer will contain "text" on return.
8d7e41661dc4633488e93b13363137523ce59977jose borrego * This function modifies the contents of buf in place and returns
8d7e41661dc4633488e93b13363137523ce59977jose borrego * a pointer to buf.
8d7e41661dc4633488e93b13363137523ce59977jose borrego while ((*q = *p++) != '\0')
8d7e41661dc4633488e93b13363137523ce59977jose borrego while (q != buf) {
8d7e41661dc4633488e93b13363137523ce59977jose borrego * Strip the characters in the set defined by class from a buffer
8d7e41661dc4633488e93b13363137523ce59977jose borrego * containing a null-terminated string.
8d7e41661dc4633488e93b13363137523ce59977jose borrego * For example, if the input buffer contained "XYA 1textZ string3"
8d7e41661dc4633488e93b13363137523ce59977jose borrego * and class contains "123XYZ", the buffer will contain "A text string"
8d7e41661dc4633488e93b13363137523ce59977jose borrego * on return.
8d7e41661dc4633488e93b13363137523ce59977jose borrego * This function modifies the contents of buf in place and returns
8d7e41661dc4633488e93b13363137523ce59977jose borrego * a pointer to buf.
8d7e41661dc4633488e93b13363137523ce59977jose borrego while (*p) {
8d7e41661dc4633488e93b13363137523ce59977jose borrego *q++ = *p++;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * trim_whitespace
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Trim leading and trailing whitespace chars (as defined by isspace)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * from a buffer. Example; if the input buffer contained " text ",
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * it will contain "text", when we return. We assume that the buffer
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * contains a null terminated string. A pointer to the buffer is
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * returned.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *p = buf;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *q = buf;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw while (*p && isspace(*p))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw while ((*q = *p++) != 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (q != buf) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw while ((--q, isspace(*q)) != 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *q = '\0';
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This is the hash mechanism used to encrypt passwords for commands like
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SamrSetUserInformation. It uses a 256 byte s-box.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned char *data,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned char *key,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned char j = 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw for (i = 0; i < DEFAULT_SBOX_SIZE; ++i)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sbox[i] = (unsigned char)i;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw for (i = 0; i < DEFAULT_SBOX_SIZE; ++i) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw for (i = 0; i < datalen; ++i) {
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * smb_chk_hostaccess
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Determines whether the specified host is in the given access list.
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * We match on aliases of the hostname as well as on the canonical name.
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * Names in the access list may be either hosts or netgroups; they're
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * not distinguished syntactically. We check for hosts first because
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * it's cheaper (just M*N strcmp()s), then try netgroups.
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * Function returns:
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * -1 for "all" (list is empty "" or "*")
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * 0 not found (host is not in the list or list is NULL)
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * 1 found
7f667e74610492ddbce8ce60f52ece95d2401949jose borregosmb_chk_hostaccess(smb_inaddr_t *ipaddr, char *access_list)
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States char *host;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States int response;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States struct nd_hostservlist *clnames;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States struct in_addr inaddr;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States struct sockaddr_in sa;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States struct netbuf buf;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States struct netconfig *config;
9b241b4ed1cf882400b069ff9853cdd310d469bfYuri Pankov /* If access list is empty or "*" - then it's "all" */
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if (*access_list == '\0' || strcmp(access_list, "*") == 0)
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States return (-1);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States if (config == NULL)
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States return (1);
9b241b4ed1cf882400b069ff9853cdd310d469bfYuri Pankov /* Try to lookup client hostname */
2807a6ec36a80c58154d9929cf429e8d6100f20aYuri Pankov clres = __netdir_getbyaddr_nosrv(config, &clnames, &buf);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States freenetconfigent(config);
9b241b4ed1cf882400b069ff9853cdd310d469bfYuri Pankov * If the list name has a '-' prepended then a match of
9b241b4ed1cf882400b069ff9853cdd310d469bfYuri Pankov * the following name implies failure instead of success.
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States if (*gr == '-') {
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States response = 0;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States } else {
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States response = 1;
9b241b4ed1cf882400b069ff9853cdd310d469bfYuri Pankov * First check if we have '@' entry, as it doesn't
9b241b4ed1cf882400b069ff9853cdd310d469bfYuri Pankov * require client hostname.
9b241b4ed1cf882400b069ff9853cdd310d469bfYuri Pankov /* Netname support */
2807a6ec36a80c58154d9929cf429e8d6100f20aYuri Pankov * No other checks can be performed if client address
2807a6ec36a80c58154d9929cf429e8d6100f20aYuri Pankov * can't be resolved.
9b241b4ed1cf882400b069ff9853cdd310d469bfYuri Pankov /* Otherwise loop through all client hostname aliases */
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States for (i = 0; i < clnames->h_cnt; i++) {
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States host = clnames->h_hostservs[i].h_host;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * If the list name begins with a dot then
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * do a domain name suffix comparison.
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * A single dot matches any name with no
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * suffix.
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States if (*gr == '.') {
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States if (strchr(host, '.') == NULL)
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States return (response);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States } else {
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States off = strlen(host) - strlen(gr);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States if (off > 0 &&
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States strcasecmp(host + off, gr) == 0) {
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States return (response);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States } else {
9b241b4ed1cf882400b069ff9853cdd310d469bfYuri Pankov /* Just do a hostname match */
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States nentries++;
2807a6ec36a80c58154d9929cf429e8d6100f20aYuri Pankov return (smb_netgroup_match(clnames, access_list, nentries));
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * smb_netgroup_match
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * Check whether any of the hostnames in clnames are
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * members (or non-members) of the netgroups in glist.
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * Since the innetgr lookup is rather expensive, the
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * result is cached. The cached entry is valid only
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * for VALID_TIME seconds. This works well because
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * typically these lookups occur in clusters when
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * a client is mounting.
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * Note that this routine establishes a host membership
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * in a list of netgroups - we've no idea just which
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * netgroup in the list it is a member of.
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * glist is a character array containing grc strings
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * representing netgroup names (optionally prefixed
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * with '-'). Each string is ended with '\0' and
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * followed immediately by the next string.
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United Statesstatic boolean_t
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United Statessmb_netgroup_match(struct nd_hostservlist *clnames, char *glist, int grc)
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States char **grl;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States char *gr;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States int nhosts = clnames->h_cnt;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States char *host;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States int i, j, n;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States boolean_t response;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States boolean_t belong = B_FALSE;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States static char *domain = NULL;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States if (domain == NULL) {
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States int ssize;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States domain = malloc(SYS_NMLN);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States if (domain == NULL)
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States return (B_FALSE);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States ssize = sysinfo(SI_SRPC_DOMAIN, domain, SYS_NMLN);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States if (ssize > SYS_NMLN) {
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States free(domain);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States domain = malloc(ssize);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States if (domain == NULL)
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States return (B_FALSE);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States ssize = sysinfo(SI_SRPC_DOMAIN, domain, ssize);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States /* Check for error in syscall or NULL domain name */
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States if (ssize <= 1)
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States return (B_FALSE);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States grl = calloc(grc, sizeof (char *));
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States if (grl == NULL)
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States return (B_FALSE);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States for (i = 0, gr = glist; i < grc && !belong; ) {
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * If the netgroup name has a '-' prepended
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * then a match of this name implies a failure
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * instead of success.
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States response = (*gr != '-') ? B_TRUE : B_FALSE;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * Subsequent names with or without a '-' (but no mix)
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * can be grouped together for a single check.
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States for (n = 0; i < grc; i++, n++, gr += strlen(gr) + 1) {
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States if ((response && *gr == '-') ||
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States (!response && *gr != '-'))
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States grl[n] = response ? gr : gr + 1;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * Check the netgroup for each
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * of the hosts names (usually just one).
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States for (j = 0; j < nhosts && !belong; j++) {
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States host = clnames->h_hostservs[j].h_host;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States if (__multi_innetgr(n, grl, 1, &host, 0, NULL,
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States 1, &domain))
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States belong = B_TRUE;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States free(grl);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States return (belong ? response : B_FALSE);
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright * Resolve the ZFS dataset from a path.
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * 0 = On success.
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * -1 = Failure to open /etc/mnttab file or to get ZFS dataset.
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wrightsmb_getdataset(const char *path, char *dataset, size_t len)
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright return (-1);
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright (void) memset(&mntpref, '\0', sizeof (mntpref));
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright * Ensure that there are no leading slashes
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright * (required for zfs_open).
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wright * The path has multiple components.
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wright * Remove the last component and try again.
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * smb_dlopen
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * Check to see if an interposer library exists. If it exists
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * and reports a valid version number and key (UUID), return
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * a handle to the library. Otherwise, return NULL.
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown typedef int (*smbex_versionfn_t)(smbex_version_t *);
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown interposer_hdl = dlopen(SMB_LIB_ALT, RTLD_NOW | RTLD_LOCAL);
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown bzero(&getversion, sizeof (smbex_versionfn_t));
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown getversion = (smbex_versionfn_t)dlsym(interposer_hdl,
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown "smbex_get_version");
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown (version = malloc(sizeof (smbex_version_t))) == NULL) {
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * smb_dlclose
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * Closes handle to the interposed library.
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * This function is a wrapper for getnameinfo() to look up a hostname given an
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * IP address. The hostname returned by this function is used for constructing
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * the service principal name field of KRB AP-REQs. Hence, it should be
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * converted to lowercase for RFC 4120 section 6.2.1 conformance.
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightsmb_getnameinfo(smb_inaddr_t *ip, char *hostname, int hostlen, int flags)
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States int rc;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright (void) memcpy(&sin6.sin6_addr.s6_addr, &ip->a_ipv6,
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if ((rc = (getnameinfo((struct sockaddr *)sp, salen,
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States hostname, hostlen, NULL, 0, flags))) == 0)
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) smb_strlwr(hostname);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States return (rc);
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * A share name is considered invalid if it contains control
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * characters or any of the following characters (MSDN 236388).
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * " / \ [ ] : | < > + ; , ? * =
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier const char *p;
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * User and group names are limited to 256 characters, cannot be terminated
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * by '.' and must not contain control characters or any of the following
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * characters.
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * " / \ [ ] < > + ; , ? * = @
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier const char *p;
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier if ((len > MAXNAMELEN) || (name[len - 1] == '.'))
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * Check a domain name for RFC 1035 and 1123 compliance. Domain names may
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * contain alphanumeric characters, hyphens and dots. The first and last
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * character of a label must be alphanumeric. Interior characters may be
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * alphanumeric or hypens.
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * Domain names should not contain underscores but we allow them because
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * Windows names are often in non-compliance with this rule.
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier const char *p;
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier if (*p == '.') {
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * A NetBIOS domain name can contain letters (a-zA-Z), numbers (0-9) and
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * It cannot:
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * - be blank or longer than 15 chracters
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * - contain all numbers
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * - be the same as the computer name
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier const char *p;
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier if (smb_getnetbiosname(netbiosname, NETBIOS_NAME_SZ) == 0) {
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * A workgroup name can contain 1 to 15 characters but cannot be the same
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * as the NetBIOS name. The name must begin with a letter or number.
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * The name cannot consist entirely of spaces or dots, which is covered
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * by the requirement that the name must begin with an alphanumeric
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * character.
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * The name must not contain control characters or any of the following
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * characters.
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * " / \ [ ] : | < > + = ; , ?
fe1c642d06e14b412cd83ae2179303186ab08972Bill Kriersmb_name_validate_workgroup(const char *workgroup)
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier const char *p;
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier if (*workgroup == '\0' || (!isalnum(*workgroup)))
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier if (smb_getnetbiosname(netbiosname, NETBIOS_NAME_SZ) == 0) {
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier if (smb_strcasecmp(workgroup, netbiosname, 0) == 0)
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States/*
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * Check for invalid characters in the given path. The list of invalid
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * characters includes control characters and the following:
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States *
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * " / \ [ ] : | < > + ; , ? * =
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States *
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * Since this is checking a path not each component, '/' is accepted
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * as separator not an invalid character, except as the first character
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * since this is supposed to be a relative path.
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States */
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United Statesuint32_t
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United Statessmb_name_validate_rpath(const char *relpath)
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States{
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States char *invalid = "\"\\[]:|<>+;,?*=";
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States char *cp;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if ((relpath == NULL) || (*relpath == '\0') || (*relpath == '/'))
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States return (ERROR_INVALID_NAME);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (strpbrk(relpath, invalid))
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States return (ERROR_INVALID_NAME);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States for (cp = (char *)relpath; *cp != '\0'; cp++) {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (iscntrl(*cp))
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States return (ERROR_INVALID_NAME);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States }
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States return (ERROR_SUCCESS);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States}
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * Parse a string to obtain the account and domain names as separate strings.
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * Names containing a backslash ('\') are known as qualified or composite
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * names. The string preceding the backslash should be the domain name
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * and the string following the slash should be a name within that domain.
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * Names that do not contain a backslash are known as isolated names.
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * An isolated name may be a single label, such as john, or may be in
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * user principal name (UPN) form, such as john@example.com.
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * domain\name
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * name@domain
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * If we encounter any of the forms above in arg, the @, / or \ separator
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * is replaced by \0 and the name and domain pointers are set to point to
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * the appropriate components in arg. Otherwise, name and domain pointers
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * will be set to NULL.
fe1c642d06e14b412cd83ae2179303186ab08972Bill Kriersmb_name_parse(char *arg, char **account, char **domain)
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier if (*p == '@') {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * The txid is an arbitrary transaction. A new txid is returned on each call.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * 0 or -1 are not assigned so that they can be used to detect
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * invalid conditions.