smb_util.c revision da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0
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
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Use is subject to license terms.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#pragma ident "%Z%%M% %I% %E% SMI"
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..
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwhexdump_offset(unsigned char *buffer, int nbytes, unsigned long *start, int log)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned char *p;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if ((p = buffer) == 0) {
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) {
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 return (0);
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) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The strsep() function locates, in the string referenced by *stringp, the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * first occurrence of any character in the string delim (or the terminating
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * `\0' character) and replaces it with a `\0'. The location of the next
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * character after the delimiter character (or NULL, if the end of the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * string was reached) is stored in *stringp. The original value of
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * *stringp is returned.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If *stringp is initially NULL, strsep() returns NULL.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw const char *spanp;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw for (tok = s; ; ) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (c == 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw s[-1] = 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw } while (sc != 0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* NOTREACHED */