smb_wksids.c revision 29bd28862cfb8abbd3a0f0a4b17e08bbc3652836
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/*
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Use is subject to license terms.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas#include <stdlib.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <string.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <synch.h>
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego#include <smbsrv/libsmb.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int wk_init = 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic rwlock_t wk_rwlock;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borregostatic char *wka_nbdomain[] = {
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego "",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego "NT Pseudo Domain",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego "NT Authority",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego "Builtin",
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright "Internet$"
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego};
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego * Predefined well known accounts table
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2easstatic smb_wka_t wka_tbl[] = {
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 0, "S-1-0-0", "Null",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego SidTypeWellKnownGroup, 0, NULL, NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 0, "S-1-1-0", "Everyone",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego SidTypeWellKnownGroup, 0, NULL, NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 0, "S-1-2-0", "Local",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego SidTypeWellKnownGroup, 0, NULL, NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 0, "S-1-3-0", "Creator Owner",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego SidTypeWellKnownGroup, 0, NULL, NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 0, "S-1-3-1", "Creator Group",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego SidTypeWellKnownGroup, 0, NULL, NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 0, "S-1-3-2", "Creator Owner Server",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego SidTypeWellKnownGroup, 0, NULL, NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 0, "S-1-3-3", "Creator Group Server",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego SidTypeWellKnownGroup, 0, NULL, NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 0, "S-1-3-4", "Owner Rights",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego SidTypeWellKnownGroup, 0, NULL, NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 1, "S-1-5", "NT Pseudo Domain",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego SidTypeDomain, 0, NULL, NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 2, "S-1-5-1", "Dialup",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego SidTypeWellKnownGroup, 0, NULL, NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 2, "S-1-5-2", "Network",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego SidTypeWellKnownGroup, 0, NULL, NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 2, "S-1-5-3", "Batch",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego SidTypeWellKnownGroup, 0, NULL, NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 2, "S-1-5-4", "Interactive",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego SidTypeWellKnownGroup, 0, NULL, NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 2, "S-1-5-6", "Service",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego SidTypeWellKnownGroup, 0, NULL, NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 2, "S-1-5-7", "Anonymous",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego SidTypeWellKnownGroup, 0, NULL, NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 2, "S-1-5-8", "Proxy",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego SidTypeWellKnownGroup, 0, NULL, NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 2, "S-1-5-9", "Enterprise Domain Controllers",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego SidTypeWellKnownGroup, 0, NULL, NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 2, "S-1-5-10", "Self",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego SidTypeWellKnownGroup, 0, NULL, NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 2, "S-1-5-11", "Authenticated Users",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego SidTypeWellKnownGroup, 0, NULL, NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 2, "S-1-5-12", "Restricted",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego SidTypeWellKnownGroup, 0, NULL, NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 2, "S-1-5-13", "Terminal Server User",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego SidTypeWellKnownGroup, 0, NULL, NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 2, "S-1-5-14", "Remote Interactive Logon",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego SidTypeWellKnownGroup, 0, NULL, NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 2, "S-1-5-15", "This Organization",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego SidTypeWellKnownGroup, 0, NULL, NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 2, "S-1-5-18", "System",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego SidTypeWellKnownGroup, 0, NULL, NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 2, "S-1-5-19", "Local Service",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego SidTypeWellKnownGroup, 0, NULL, NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 2, "S-1-5-20", "Network Service",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego SidTypeWellKnownGroup, 0, NULL, NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 2, "S-1-5-33", "Write Restricted",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego SidTypeWellKnownGroup, 0, NULL, NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 2, "S-1-5-1000", "Other Organization",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego SidTypeWellKnownGroup, 0, NULL, NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 3, "S-1-5-32", "Builtin",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego SidTypeDomain, 0, NULL, NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 4, "S-1-7", "Internet$",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego SidTypeDomain, 0, NULL, NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 3, "S-1-5-32-544", "Administrators", SidTypeAlias,
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas SMB_WKAFLG_LGRP_ENABLE,
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas "Members can fully administer the computer/domain", NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 3, "S-1-5-32-545", "Users",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego SidTypeAlias, 0, NULL, NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 3, "S-1-5-32-546", "Guests",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego SidTypeAlias, 0, NULL, NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 3, "S-1-5-32-547", "Power Users", SidTypeAlias,
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas SMB_WKAFLG_LGRP_ENABLE, "Members can share directories", NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 3, "S-1-5-32-548", "Account Operators",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego SidTypeAlias, 0, NULL, NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 3, "S-1-5-32-549", "Server Operators",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego SidTypeAlias, 0, NULL, NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 3, "S-1-5-32-550", "Print Operators",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego SidTypeAlias, 0, NULL, NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 3, "S-1-5-32-551", "Backup Operators", SidTypeAlias,
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas SMB_WKAFLG_LGRP_ENABLE,
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas "Members can bypass file security to back up files", NULL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { 3, "S-1-5-32-552", "Replicator",
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego SidTypeAlias, 0, NULL, NULL }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw};
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas#define SMB_WKA_NUM (sizeof (wka_tbl)/sizeof (wka_tbl[0]))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego * Looks up well known accounts table for the given SID.
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego * Upon success returns a pointer to the account entry in
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego * the table, otherwise returns NULL.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
7f667e74610492ddbce8ce60f52ece95d2401949jose borregosmb_wka_t *
7f667e74610492ddbce8ce60f52ece95d2401949jose borregosmb_wka_lookup_sid(smb_sid_t *sid)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas smb_wka_t *entry;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int i;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego (void) rw_rdlock(&wk_rwlock);
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas for (i = 0; i < SMB_WKA_NUM; ++i) {
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas entry = &wka_tbl[i];
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas if (smb_sid_cmp(sid, entry->wka_binsid)) {
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego (void) rw_unlock(&wk_rwlock);
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego return (entry);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego (void) rw_unlock(&wk_rwlock);
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas return (NULL);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego * Looks up well known accounts table for the given name.
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego * Upon success returns a pointer to the binary SID of the
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego * entry, otherwise returns NULL.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eassmb_sid_t *
7f667e74610492ddbce8ce60f52ece95d2401949jose borregosmb_wka_get_sid(char *name)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas smb_wka_t *entry;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego smb_sid_t *sid = NULL;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego if ((entry = smb_wka_lookup_name(name)) != NULL)
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego sid = entry->wka_binsid;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego return (sid);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego * Looks up well known accounts table for the given name.
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego * Upon success returns a pointer to the account entry in
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego * the table, otherwise returns NULL.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eassmb_wka_t *
7f667e74610492ddbce8ce60f52ece95d2401949jose borregosmb_wka_lookup_name(char *name)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas smb_wka_t *entry;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int i;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) rw_rdlock(&wk_rwlock);
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas for (i = 0; i < SMB_WKA_NUM; ++i) {
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas entry = &wka_tbl[i];
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas if (!utf8_strcasecmp(name, entry->wka_name)) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) rw_unlock(&wk_rwlock);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (entry);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) rw_unlock(&wk_rwlock);
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas return (NULL);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego/*
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego * Returns the Netbios domain name for the given index
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego */
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borregochar *
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borregosmb_wka_get_domain(int idx)
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego{
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego if ((idx >= 0) && (idx < SMB_WKA_NUM))
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego return (wka_nbdomain[idx]);
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas return (NULL);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright/*
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * This function adds well known groups to groups in a user's
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * access token (gids).
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright *
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * "Network" SID is added for all users connecting over CIFS.
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright *
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * "Authenticated Users" SID is added for all users except Guest
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * and Anonymous.
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright *
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * "Guests" SID is added for guest users and Administrators SID
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * is added for admin users.
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright */
7f667e74610492ddbce8ce60f52ece95d2401949jose borregouint32_t
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightsmb_wka_token_groups(uint32_t flags, smb_ids_t *gids)
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego{
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego smb_id_t *id;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego int total_cnt;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright total_cnt = gids->i_cnt + 3;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego gids->i_ids = realloc(gids->i_ids, total_cnt * sizeof (smb_id_t));
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego if (gids->i_ids == NULL)
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego return (NT_STATUS_NO_MEMORY);
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego id = gids->i_ids + gids->i_cnt;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright id->i_sid = smb_sid_dup(smb_wka_get_sid("Network"));
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright id->i_attrs = 0x7;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if (id->i_sid == NULL)
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright return (NT_STATUS_NO_MEMORY);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright id++;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright gids->i_cnt++;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if ((flags & SMB_ATF_ANON) == 0) {
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if (flags & SMB_ATF_GUEST)
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright id->i_sid = smb_sid_dup(smb_wka_get_sid("Guests"));
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright else
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright id->i_sid =
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright smb_sid_dup(smb_wka_get_sid("Authenticated Users"));
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright id->i_attrs = 0x7;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if (id->i_sid == NULL)
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright return (NT_STATUS_NO_MEMORY);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright id++;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright gids->i_cnt++;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright }
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if (flags & SMB_ATF_ADMIN) {
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright id->i_sid = smb_sid_dup(smb_wka_get_sid("Administrators"));
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego id->i_attrs = 0x7;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego if (id->i_sid == NULL)
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego return (NT_STATUS_NO_MEMORY);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright gids->i_cnt++;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego }
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego return (NT_STATUS_SUCCESS);
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego}
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas * smb_wka_init
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Generate binary SIDs from the string SIDs in the table
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * and set the proper field.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Caller MUST not store the binary SID pointer anywhere that
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * could lead to freeing it.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This function should only be called once.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwint
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eassmb_wka_init(void)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas smb_wka_t *entry;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int i;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) rw_wrlock(&wk_rwlock);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (wk_init) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) rw_unlock(&wk_rwlock);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas for (i = 0; i < SMB_WKA_NUM; ++i) {
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas entry = &wka_tbl[i];
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas entry->wka_binsid = smb_sid_fromstr(entry->wka_sid);
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas if (entry->wka_binsid == NULL) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) rw_unlock(&wk_rwlock);
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas smb_wka_fini();
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw wk_init = 1;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) rw_unlock(&wk_rwlock);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwvoid
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eassmb_wka_fini(void)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int i;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) rw_wrlock(&wk_rwlock);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (wk_init == 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) rw_unlock(&wk_rwlock);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas for (i = 0; i < SMB_WKA_NUM; ++i) {
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas if (wka_tbl[i].wka_binsid) {
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas free(wka_tbl[i].wka_binsid);
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas wka_tbl[i].wka_binsid = NULL;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw wk_init = 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) rw_unlock(&wk_rwlock);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}