smb_util.c revision fc724630b14603e4c1147df68b7bf45f7de7431f
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER START
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
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 *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * or http://www.opensolaris.org/os/licensing.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * See the License for the specific language governing permissions
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * and limitations under the License.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
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 *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER END
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Use is subject to license terms.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <ctype.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <stdio.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <string.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <stdlib.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <pthread.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <sys/varargs.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <sys/types.h>
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright#include <sys/mnttab.h>
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>
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright#include <libzfs.h>
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright#include <smbsrv/string.h>
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright#include <smbsrv/libsmb.h>
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States
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 States
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
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define C2H(c) "0123456789ABCDEF"[(c)]
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define H2C(c) (((c) >= '0' && (c) <= '9') ? ((c) - '0') : \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ((c) >= 'a' && (c) <= 'f') ? ((c) - 'a' + 10) : \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ((c) >= 'A' && (c) <= 'F') ? ((c) - 'A' + 10) : \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw '\0')
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define DEFAULT_SBOX_SIZE 256
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * hexdump
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
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 *
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..
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwvoid
dc20a3024900c47dd2ee44b9707e6df38f7d62a5ashexdump_offset(unsigned char *buffer, int nbytes, unsigned long *start)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw static char *hex = "0123456789ABCDEF";
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int i, count;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int offset;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned char *p;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char ascbuf[64];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char hexbuf[64];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *ap = ascbuf;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *hp = hexbuf;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if ((p = buffer) == NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw offset = *start;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *ap = '\0';
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *hp = '\0';
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw count = 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw for (i = 0; i < nbytes; ++i) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (i && (i % 16) == 0) {
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as smb_tracef("%06X %s %s", offset, hexbuf, ascbuf);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ap = ascbuf;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw hp = hexbuf;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw count = 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw offset += 16;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ap += sprintf(ap, "%c",
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (*p >= 0x20 && *p < 0x7F) ? *p : '.');
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw hp += sprintf(hp, " %c%c",
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw hex[(*p >> 4) & 0x0F], hex[(*p & 0x0F)]);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ++p;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ++count;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (count) {
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as smb_tracef("%06X %-48s %s", offset, hexbuf, ascbuf);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw offset += count;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *start = offset;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwvoid
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwhexdump(unsigned char *buffer, int nbytes)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned long start = 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as hexdump_offset(buffer, nbytes, &start);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * bintohex
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Converts the given binary data (srcbuf) to
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * its equivalent hex chars (hexbuf).
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
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 */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsize_t
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwbintohex(const char *srcbuf, size_t srclen,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *hexbuf, size_t hexlen)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw size_t outlen;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char c;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw outlen = srclen << 1;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (hexlen < outlen)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw while (srclen-- > 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw c = *srcbuf++;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *hexbuf++ = C2H(c & 0xF);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *hexbuf++ = C2H((c >> 4) & 0xF);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (outlen);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * hextobin
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Converts hex to binary.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
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 *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * hexlen should be an even number.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * dstlen should be at least half of hexlen.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
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 */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsize_t
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwhextobin(const char *hexbuf, size_t hexlen,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *dstbuf, size_t dstlen)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw size_t outlen;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if ((hexlen % 2) != 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw outlen = hexlen >> 1;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (dstlen < outlen)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw while (hexlen > 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *dstbuf = H2C(*hexbuf) & 0x0F;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw hexbuf++;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *dstbuf++ |= (H2C(*hexbuf) << 4) & 0xF0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw hexbuf++;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw hexlen -= 2;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (outlen);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
8d7e41661dc4633488e93b13363137523ce59977jose borrego/*
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 *
8d7e41661dc4633488e93b13363137523ce59977jose borrego * This function modifies the contents of buf in place and returns
8d7e41661dc4633488e93b13363137523ce59977jose borrego * a pointer to buf.
8d7e41661dc4633488e93b13363137523ce59977jose borrego */
8d7e41661dc4633488e93b13363137523ce59977jose borregochar *
8d7e41661dc4633488e93b13363137523ce59977jose borregostrtrim(char *buf, const char *class)
8d7e41661dc4633488e93b13363137523ce59977jose borrego{
8d7e41661dc4633488e93b13363137523ce59977jose borrego char *p = buf;
8d7e41661dc4633488e93b13363137523ce59977jose borrego char *q = buf;
8d7e41661dc4633488e93b13363137523ce59977jose borrego
8d7e41661dc4633488e93b13363137523ce59977jose borrego if (buf == NULL)
8d7e41661dc4633488e93b13363137523ce59977jose borrego return (NULL);
8d7e41661dc4633488e93b13363137523ce59977jose borrego
8d7e41661dc4633488e93b13363137523ce59977jose borrego p += strspn(p, class);
8d7e41661dc4633488e93b13363137523ce59977jose borrego
8d7e41661dc4633488e93b13363137523ce59977jose borrego if (p != buf) {
8d7e41661dc4633488e93b13363137523ce59977jose borrego while ((*q = *p++) != '\0')
8d7e41661dc4633488e93b13363137523ce59977jose borrego ++q;
8d7e41661dc4633488e93b13363137523ce59977jose borrego }
8d7e41661dc4633488e93b13363137523ce59977jose borrego
8d7e41661dc4633488e93b13363137523ce59977jose borrego while (q != buf) {
8d7e41661dc4633488e93b13363137523ce59977jose borrego --q;
8d7e41661dc4633488e93b13363137523ce59977jose borrego if (strspn(q, class) == 0)
8d7e41661dc4633488e93b13363137523ce59977jose borrego return (buf);
8d7e41661dc4633488e93b13363137523ce59977jose borrego *q = '\0';
8d7e41661dc4633488e93b13363137523ce59977jose borrego }
8d7e41661dc4633488e93b13363137523ce59977jose borrego
8d7e41661dc4633488e93b13363137523ce59977jose borrego return (buf);
8d7e41661dc4633488e93b13363137523ce59977jose borrego}
8d7e41661dc4633488e93b13363137523ce59977jose borrego
8d7e41661dc4633488e93b13363137523ce59977jose borrego/*
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 *
8d7e41661dc4633488e93b13363137523ce59977jose borrego * This function modifies the contents of buf in place and returns
8d7e41661dc4633488e93b13363137523ce59977jose borrego * a pointer to buf.
8d7e41661dc4633488e93b13363137523ce59977jose borrego */
8d7e41661dc4633488e93b13363137523ce59977jose borregochar *
8d7e41661dc4633488e93b13363137523ce59977jose borregostrstrip(char *buf, const char *class)
8d7e41661dc4633488e93b13363137523ce59977jose borrego{
8d7e41661dc4633488e93b13363137523ce59977jose borrego char *p = buf;
8d7e41661dc4633488e93b13363137523ce59977jose borrego char *q = buf;
8d7e41661dc4633488e93b13363137523ce59977jose borrego
8d7e41661dc4633488e93b13363137523ce59977jose borrego if (buf == NULL)
8d7e41661dc4633488e93b13363137523ce59977jose borrego return (NULL);
8d7e41661dc4633488e93b13363137523ce59977jose borrego
8d7e41661dc4633488e93b13363137523ce59977jose borrego while (*p) {
8d7e41661dc4633488e93b13363137523ce59977jose borrego p += strspn(p, class);
8d7e41661dc4633488e93b13363137523ce59977jose borrego *q++ = *p++;
8d7e41661dc4633488e93b13363137523ce59977jose borrego }
8d7e41661dc4633488e93b13363137523ce59977jose borrego
8d7e41661dc4633488e93b13363137523ce59977jose borrego *q = '\0';
8d7e41661dc4633488e93b13363137523ce59977jose borrego return (buf);
8d7e41661dc4633488e93b13363137523ce59977jose borrego}
8d7e41661dc4633488e93b13363137523ce59977jose borrego
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * trim_whitespace
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
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 */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwchar *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwtrim_whitespace(char *buf)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *p = buf;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *q = buf;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (buf == NULL)
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as return (NULL);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw while (*p && isspace(*p))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ++p;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw while ((*q = *p++) != 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ++q;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (q != buf) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw while ((--q, isspace(*q)) != 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *q = '\0';
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (buf);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * randomize
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Randomize the contents of the specified buffer.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwvoid
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwrandomize(char *data, unsigned len)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned dwlen = len / 4;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned remlen = len % 4;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned tmp;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned i; /*LINTED E_BAD_PTR_CAST_ALIGN*/
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned *p = (unsigned *)data;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw for (i = 0; i < dwlen; ++i)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *p++ = random();
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (remlen) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw tmp = random();
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) memcpy(p, &tmp, remlen);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This is the hash mechanism used to encrypt passwords for commands like
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SamrSetUserInformation. It uses a 256 byte s-box.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwvoid
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwrand_hash(
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned char *data,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw size_t datalen,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned char *key,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw size_t keylen)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned char sbox[DEFAULT_SBOX_SIZE];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned char tmp;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned char index_i = 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned char index_j = 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned char j = 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int i;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw for (i = 0; i < DEFAULT_SBOX_SIZE; ++i)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sbox[i] = (unsigned char)i;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw for (i = 0; i < DEFAULT_SBOX_SIZE; ++i) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw j += (sbox[i] + key[i % keylen]);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw tmp = sbox[i];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sbox[i] = sbox[j];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sbox[j] = tmp;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw for (i = 0; i < datalen; ++i) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw index_i++;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw index_j += sbox[index_i];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw tmp = sbox[index_i];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sbox[index_i] = sbox[index_j];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sbox[index_j] = tmp;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw tmp = sbox[index_i] + sbox[index_j];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw data[i] = data[i] ^ sbox[tmp];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States/*
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * smb_chk_hostaccess
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States *
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.
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States *
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego * Currently this function always returns B_TRUE for ipv6 until
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego * the underlying functions support ipv6
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego *
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 borrego *
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States */
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United Statesint
7f667e74610492ddbce8ce60f52ece95d2401949jose borregosmb_chk_hostaccess(smb_inaddr_t *ipaddr, char *access_list)
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States{
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 i;
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
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego if (ipaddr->a_family == AF_INET6)
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego return (B_TRUE);
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego inaddr.s_addr = ipaddr->a_ipv4;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States /*
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * If no access list - then it's "all"
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States */
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
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States nentries = 0;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States
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
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
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
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 }
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States freenetconfigent(config);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States
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
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States /*
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 */
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 gr++;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States } else {
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States response = 1;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States }
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States /*
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 */
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 /*
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 */
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 }
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States }
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States } else {
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States /*
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 */
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 /*
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * Just do a hostname match
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States */
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 }
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States }
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States }
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States nentries++;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States }
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States netgroup_match = smb_netgroup_match(clnames, access_list, nentries);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States return (netgroup_match);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States}
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States/*
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * smb_make_mask
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States *
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 States */
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{
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
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States /*
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 *
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * @109.104.56/28
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States *
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 *
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * @109.104 or @109.104.0.0
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States */
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 : 0;
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 else
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States mask = IN_CLASSE_NET;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States }
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States return (mask);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States}
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States/*
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * smb_netmatch
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States *
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 States */
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States
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{
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 int i;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States char buff[256];
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States /*
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * Check if it's an IPv4 addr
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States */
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
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
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
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States if (isdigit(*name)) {
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States /*
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 */
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 break;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States p++;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States }
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States } else {
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States /*
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 */
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 }
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States addr = np->n_net;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States }
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States
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}
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States/*
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * smb_netgroup_match
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States *
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 *
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 *
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 States */
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{
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
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
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
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 }
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 }
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States
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
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States for (i = 0, gr = glist; i < grc && !belong; ) {
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States /*
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 */
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States response = (*gr != '-') ? B_TRUE : B_FALSE;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States /*
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 */
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 break;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States grl[n] = response ? gr : gr + 1;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States }
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States /*
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 */
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 }
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States }
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States free(grl);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States return (belong ? response : B_FALSE);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States}
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright/*
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright * Resolve the ZFS dataset from a path.
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright */
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wrightint
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wrightsmb_getdataset(const char *path, char *dataset, size_t len)
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright{
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright char tmppath[MAXPATHLEN];
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright char *cp;
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright FILE *fp;
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright struct mnttab mnttab;
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright struct mnttab mntpref;
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright int rc = -1;
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright if ((fp = fopen(MNTTAB, "r")) == NULL)
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright return (-1);
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright (void) memset(&mnttab, '\0', sizeof (mnttab));
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright (void) strlcpy(tmppath, path, MAXPATHLEN);
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright cp = tmppath;
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright while (*cp != '\0') {
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright resetmnttab(fp);
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright (void) memset(&mntpref, '\0', sizeof (mntpref));
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright mntpref.mnt_mountp = tmppath;
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright mntpref.mnt_fstype = "zfs";
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright if (getmntany(fp, &mnttab, &mntpref) == 0) {
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright /*
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright * Ensure that there are no leading slashes
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright * (required for zfs_open).
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright */
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright cp = mnttab.mnt_special;
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright cp += strspn(cp, "/");
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright (void) strlcpy(dataset, cp, len);
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright rc = 0;
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright break;
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright }
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wright if (strcmp(tmppath, "/") == 0)
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wright break;
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wright
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wright if ((cp = strrchr(tmppath, '/')) == NULL)
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wright break;
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wright
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wright /*
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wright * The path has multiple components.
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wright * Remove the last component and try again.
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wright */
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wright *cp = '\0';
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wright if (tmppath[0] == '\0')
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wright (void) strcpy(tmppath, "/");
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright cp = tmppath;
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright }
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright (void) fclose(fp);
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright return (rc);
6d57f8333dfc689618aaf2efe76a8066de053841Alan Wright}