1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * CDDL HEADER START
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * The contents of this file are subject to the terms of the
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * Common Development and Distribution License (the "License").
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * You may not use this file except in compliance with the License.
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * See the License for the specific language governing permissions
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * and limitations under the License.
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * When distributing Covered Code, include this CDDL HEADER in each
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * If applicable, add the following below this CDDL HEADER, with the
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * fields enclosed by brackets "[]" replaced with your own identifying
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * information: Portions Copyright [yyyy] [name of copyright owner]
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * CDDL HEADER END
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * Use is subject to license terms.
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * This is an extract from usr/src/common/smbsrv/smb_sid.c,
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * with functions renamed as part of a tentative plan for convergence.
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown#else /* _KERNEL */
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown#endif /* _KERNEL */
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * Returns the number of bytes required to hold the sid.
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * Fill in the passed buffer with the string form of the given
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * binary sid.
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown for (i = 0; i < NT_SID_AUTH_MAX; ++i) {
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown if (sid->sid_authority[i] != 0 || i == NT_SID_AUTH_MAX - 1) {
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown (void) sprintf(p, "%d", sid->sid_authority[i]);
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown for (i = 0; i < sid->sid_subauthcnt && i < NT_SID_SUBAUTH_MAX; ++i) {
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * sid_fromstr
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * Converts a SID in string form to a SID structure. There are lots of
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * simplifying assumptions in here. The memory for the SID is allocated
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * as if it was the largest possible SID; the caller is responsible for
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * freeing the memory when it is no longer required. We assume that the
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * string starts with "S-1-" and that the authority is held in the last
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * byte, which should be okay for most situations. It also assumes the
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * sub-authorities are in decimal format.
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * On success, a pointer to a SID is returned. Otherwise a null pointer
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * is returned.
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown size = sizeof (sid_t) + (NT_SID_SUBAUTH_MAX * sizeof (uint32_t));
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown for (i = 0, p = &sidstr[5]; i < NT_SID_SUBAUTH_MAX && *p; ++i) {
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown while (*p && *p == '-')
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown while (*p && *p != '-')
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown for (i = 0; i < sid->sid_subauthcnt && i < NT_SID_SUBAUTH_MAX; ++i) {
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown p[0] = v & 0xff;
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown for (i = 0; i < sid->sid_subauthcnt && i < NT_SID_SUBAUTH_MAX; ++i) {
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown v = p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);