smb_util.c revision fe1c642d06e14b412cd83ae2179303186ab08972
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
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Use is subject to license terms.
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 uint_t smb_make_mask(char *, uint_t);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United Statesstatic boolean_t smb_netmatch(struct netbuf *, char *);
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 __multi_innetgr();
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 unsigned long start = 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 * randomize
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Randomize the contents of the specified buffer.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned i; /*LINTED E_BAD_PTR_CAST_ALIGN*/
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned *p = (unsigned *)data;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw for (i = 0; i < dwlen; ++i)
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 tmp;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned char index_i = 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned char index_j = 0;
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
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * Determine whether an access list grants rights to a particular host.
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.
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego * Currently this function always returns B_TRUE for ipv6 until
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego * the underlying functions support ipv6
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * Function returns:
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * -1 for "all"
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * 0 not found
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 int nentries;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States char *gr;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States char *lasts;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States char *host;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States int off;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States int netgroup_match;
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;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * If no access list - then it's "all"
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States if (access_list == NULL || *access_list == '\0' ||
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States strcmp(access_list, "*") == 0)
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States return (-1);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States nentries = 0;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States sa.sin_family = AF_INET;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States sa.sin_port = 0;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States sa.sin_addr = inaddr;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States buf.len = buf.maxlen = sizeof (sa);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States buf.buf = (char *)&sa;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States config = getnetconfigent("tcp");
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States if (config == NULL)
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States return (1);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States if (__netdir_getbyaddr_nosrv(config, &clnames, &buf)) {
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States freenetconfigent(config);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States return (0);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States freenetconfigent(config);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States for (gr = strtok_r(access_list, ":", &lasts);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States gr != NULL; gr = strtok_r(NULL, ":", &lasts)) {
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * If the list name has a '-' prepended
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * then a match of the following name
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * 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;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * The following loops through all the
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * client's aliases. Usually it's just one name.
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 (*(gr + 1) == '\0') { /* single dot */
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 {
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * If the list name begins with an at
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * sign then do a network comparison.
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States if (*gr == '@') {
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States if (smb_netmatch(&buf, gr + 1))
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States return (response);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States } else {
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * Just do a hostname match
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States if (strcasecmp(gr, host) == 0)
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States return (response);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States nentries++;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States netgroup_match = smb_netgroup_match(clnames, access_list, nentries);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States return (netgroup_match);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * smb_make_mask
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * Construct a mask for an IPv4 address using the @<dotted-ip>/<len>
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * syntax or use the default mask for the IP address.
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United Statesstatic uint_t
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United Statessmb_make_mask(char *maskstr, uint_t addr)
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States uint_t mask;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States uint_t bits;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * If the mask is specified explicitly then
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * use that value, e.g.
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * @109.104.56/28
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * otherwise assume a mask from the zero octets
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * in the least significant bits of the address, e.g.
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * @109.104 or @109.104.0.0
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States if (maskstr) {
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States bits = atoi(maskstr);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States mask = bits ? ~0 << ((sizeof (struct in_addr) * NBBY) - bits)
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States addr &= mask;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States } else {
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States if ((addr & IN_CLASSA_HOST) == 0)
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States mask = IN_CLASSA_NET;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States else if ((addr & IN_CLASSB_HOST) == 0)
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States mask = IN_CLASSB_NET;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States else if ((addr & IN_CLASSC_HOST) == 0)
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States mask = IN_CLASSC_NET;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States mask = IN_CLASSE_NET;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States return (mask);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * smb_netmatch
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * Check to see if the address in the netbuf matches the "net"
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * specified by name. The format of "name" can be:
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * fully qualified domain name
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * dotted IP address
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * dotted IP address followed by '/<len>'
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * See sharen_nfs(1M) for details.
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United Statesstatic boolean_t
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United Statessmb_netmatch(struct netbuf *nb, char *name)
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States uint_t claddr;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States struct netent n, *np;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States char *mp, *p;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States uint_t addr, mask;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States char buff[256];
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * Check if it's an IPv4 addr
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States if (nb->len != sizeof (struct sockaddr_in))
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States return (B_FALSE);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States (void) memcpy(&claddr,
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States /* LINTED pointer alignment */
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States &((struct sockaddr_in *)nb->buf)->sin_addr.s_addr,
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States sizeof (struct in_addr));
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States claddr = ntohl(claddr);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States mp = strchr(name, '/');
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States if (mp)
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States *mp++ = '\0';
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States if (isdigit(*name)) {
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * Convert a dotted IP address
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * to an IP address. The conversion
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * is not the same as that in inet_addr().
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States p = name;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States addr = 0;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States for (i = 0; i < 4; i++) {
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States addr |= atoi(p) << ((3-i) * 8);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States p = strchr(p, '.');
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States if (p == NULL)
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States } else {
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * Turn the netname into
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * an IP address.
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States np = getnetbyname_r(name, &n, buff, sizeof (buff));
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States if (np == NULL) {
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States return (B_FALSE);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States addr = np->n_net;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States mask = smb_make_mask(mp, addr);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States return ((claddr & mask) == addr);
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.
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * Returns the hostname given the IP address. Wrapper for getnameinfo.
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightsmb_getnameinfo(smb_inaddr_t *ip, char *hostname, int hostlen, int flags)
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright (void) memcpy(&sin6.sin6_addr.s6_addr, &ip->a_ipv6,
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright return (getnameinfo((struct sockaddr *)sp, salen,
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)
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 == '@') {