xref: /titanic_52/usr/src/cmd/idmap/idmapd/wksids.c (revision 9fb67ea305c66b6a297583b9b0db6796b0dfe497)
11fcced4cSJordan Brown /*
21fcced4cSJordan Brown  * CDDL HEADER START
31fcced4cSJordan Brown  *
41fcced4cSJordan Brown  * The contents of this file are subject to the terms of the
51fcced4cSJordan Brown  * Common Development and Distribution License (the "License").
61fcced4cSJordan Brown  * You may not use this file except in compliance with the License.
71fcced4cSJordan Brown  *
81fcced4cSJordan Brown  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
91fcced4cSJordan Brown  * or http://www.opensolaris.org/os/licensing.
101fcced4cSJordan Brown  * See the License for the specific language governing permissions
111fcced4cSJordan Brown  * and limitations under the License.
121fcced4cSJordan Brown  *
131fcced4cSJordan Brown  * When distributing Covered Code, include this CDDL HEADER in each
141fcced4cSJordan Brown  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
151fcced4cSJordan Brown  * If applicable, add the following below this CDDL HEADER, with the
161fcced4cSJordan Brown  * fields enclosed by brackets "[]" replaced with your own identifying
171fcced4cSJordan Brown  * information: Portions Copyright [yyyy] [name of copyright owner]
181fcced4cSJordan Brown  *
191fcced4cSJordan Brown  * CDDL HEADER END
201fcced4cSJordan Brown  */
211fcced4cSJordan Brown 
221fcced4cSJordan Brown /*
23*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
241fcced4cSJordan Brown  * Use is subject to license terms.
251fcced4cSJordan Brown  */
261fcced4cSJordan Brown 
271fcced4cSJordan Brown /*
281fcced4cSJordan Brown  * Information about well-known (builtin) names, and functions to retrieve
291fcced4cSJordan Brown  * information about them.
301fcced4cSJordan Brown  */
311fcced4cSJordan Brown 
321fcced4cSJordan Brown #include <assert.h>
331fcced4cSJordan Brown #include <string.h>
341fcced4cSJordan Brown #include "idmapd.h"
351fcced4cSJordan Brown #include "miscutils.h"
361fcced4cSJordan Brown 
371fcced4cSJordan Brown /*
381fcced4cSJordan Brown  * Table for well-known SIDs.
391fcced4cSJordan Brown  *
401fcced4cSJordan Brown  * Background:
411fcced4cSJordan Brown  *
421fcced4cSJordan Brown  * Some of the well-known principals are stored under:
431fcced4cSJordan Brown  * cn=WellKnown Security Principals, cn=Configuration, dc=<forestRootDomain>
441fcced4cSJordan Brown  * They belong to objectClass "foreignSecurityPrincipal". They don't have
451fcced4cSJordan Brown  * "samAccountName" nor "userPrincipalName" attributes. Their names are
461fcced4cSJordan Brown  * available in "cn" and "name" attributes. Some of these principals have a
471fcced4cSJordan Brown  * second entry under CN=ForeignSecurityPrincipals,dc=<forestRootDomain> and
481fcced4cSJordan Brown  * these duplicate entries have the stringified SID in the "name" and "cn"
491fcced4cSJordan Brown  * attributes instead of the actual name.
501fcced4cSJordan Brown  *
511fcced4cSJordan Brown  * Those of the form S-1-5-32-X are Builtin groups and are stored in the
521fcced4cSJordan Brown  * cn=builtin container (except, Power Users which is not stored in AD)
531fcced4cSJordan Brown  *
541fcced4cSJordan Brown  * These principals are and will remain constant. Therefore doing AD lookups
551fcced4cSJordan Brown  * provides no benefit. Also, using hard-coded table (and thus avoiding AD
561fcced4cSJordan Brown  * lookup) improves performance and avoids additional complexity in the
571fcced4cSJordan Brown  * adutils.c code. Moreover these SIDs can be used when no Active Directory
581fcced4cSJordan Brown  * is available (such as the CIFS server's "workgroup" mode).
591fcced4cSJordan Brown  *
601fcced4cSJordan Brown  * Notes:
611fcced4cSJordan Brown  * 1. Currently we don't support localization of well-known SID names,
621fcced4cSJordan Brown  * unlike Windows.
631fcced4cSJordan Brown  *
641fcced4cSJordan Brown  * 2. Other well-known SIDs i.e. S-1-5-<domain>-<w-k RID> are not stored
651fcced4cSJordan Brown  * here. AD does have normal user/group objects for these objects and
661fcced4cSJordan Brown  * can be looked up using the existing AD lookup code.
671fcced4cSJordan Brown  *
681fcced4cSJordan Brown  * 3. See comments above lookup_wksids_sid2pid() for more information
691fcced4cSJordan Brown  * on how we lookup the wksids table.
701fcced4cSJordan Brown  *
711fcced4cSJordan Brown  * 4. If this table contains two entries for a particular Windows name,
721fcced4cSJordan Brown  * so as to offer both UID and GID mappings, the preferred mapping (the
731fcced4cSJordan Brown  * one that matches Windows usage) must be listed first.  That is the
741fcced4cSJordan Brown  * entry that will be used when the caller specifies IDMAP_POSIXID
751fcced4cSJordan Brown  * ("don't care") as the target.
761fcced4cSJordan Brown  *
771fcced4cSJordan Brown  * Entries here come from KB243330, MS-LSAT, and
781fcced4cSJordan Brown  * http://technet.microsoft.com/en-us/library/cc755854.aspx
791fcced4cSJordan Brown  * http://technet.microsoft.com/en-us/library/cc755925.aspx
801fcced4cSJordan Brown  * http://msdn.microsoft.com/en-us/library/cc980032(PROT.10).aspx
811fcced4cSJordan Brown  */
821fcced4cSJordan Brown static wksids_table_t wksids[] = {
831fcced4cSJordan Brown 	/* S-1-0	Null Authority */
84*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{"S-1-0", 0, "", "Nobody", 1, IDMAP_SENTINEL_PID, -1, 1},
851fcced4cSJordan Brown 
861fcced4cSJordan Brown 	/* S-1-1	World Authority */
87*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{"S-1-1", 0, "", "Everyone", 0, IDMAP_SENTINEL_PID, -1, -1},
881fcced4cSJordan Brown 
891fcced4cSJordan Brown 	/* S-1-2	Local Authority */
90*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{"S-1-2", 0, "", "Local", 0, IDMAP_SENTINEL_PID, -1, -1},
91*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{"S-1-2", 1, "", "Console Logon", 0, IDMAP_SENTINEL_PID, -1, -1},
921fcced4cSJordan Brown 
931fcced4cSJordan Brown 	/* S-1-3	Creator Authority */
941fcced4cSJordan Brown 	{"S-1-3", 0, "", "Creator Owner", 1, IDMAP_WK_CREATOR_OWNER_UID, 1, 0},
951fcced4cSJordan Brown 	{"S-1-3", 1, "", "Creator Group", 0, IDMAP_WK_CREATOR_GROUP_GID, 0, 0},
96*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{"S-1-3", 2, "", "Creator Owner Server", 1, IDMAP_SENTINEL_PID, -1, -1},
97*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{"S-1-3", 3, "", "Creator Group Server", 0, IDMAP_SENTINEL_PID, -1, 1},
98*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{"S-1-3", 4, "", "Owner Rights", 0, IDMAP_SENTINEL_PID, -1, -1},
991fcced4cSJordan Brown 
1001fcced4cSJordan Brown 	/* S-1-4	Non-unique Authority */
1011fcced4cSJordan Brown 
1021fcced4cSJordan Brown 	/* S-1-5	NT Authority */
103*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{"S-1-5", 1, "", "Dialup", 0, IDMAP_SENTINEL_PID, -1, -1},
104*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{"S-1-5", 2, "", "Network", 0, IDMAP_SENTINEL_PID, -1, -1},
105*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{"S-1-5", 3, "", "Batch", 0, IDMAP_SENTINEL_PID, -1, -1},
106*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{"S-1-5", 4, "", "Interactive", 0, IDMAP_SENTINEL_PID, -1, -1},
1071fcced4cSJordan Brown 	/* S-1-5-5-X-Y	Logon Session */
108*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{"S-1-5", 6, "", "Service", 0, IDMAP_SENTINEL_PID, -1, -1},
1091fcced4cSJordan Brown 	{"S-1-5", 7, "", "Anonymous Logon", 0, GID_NOBODY, 0, 0},
1101fcced4cSJordan Brown 	{"S-1-5", 7, "", "Anonymous Logon", 0, UID_NOBODY, 1, 0},
111*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{"S-1-5", 8, "", "Proxy", 0, IDMAP_SENTINEL_PID, -1, -1},
1121fcced4cSJordan Brown 	{"S-1-5", 9, "", "Enterprise Domain Controllers", 0,
113*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	    IDMAP_SENTINEL_PID, -1, -1},
114*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{"S-1-5", 10, "", "Self", 0, IDMAP_SENTINEL_PID, -1, -1},
115*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{"S-1-5", 11, "", "Authenticated Users", 0, IDMAP_SENTINEL_PID, -1, -1},
116*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{"S-1-5", 12, "", "Restricted", 0, IDMAP_SENTINEL_PID, -1, -1},
117*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{"S-1-5", 13, "", "Terminal Server Users", 0,
118*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	    IDMAP_SENTINEL_PID, -1, -1},
119*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{"S-1-5", 14, "", "Remote Interactive Logon", 0,
120*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	    IDMAP_SENTINEL_PID, -1, -1},
121*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{"S-1-5", 15, "", "This Organization", 0, IDMAP_SENTINEL_PID, -1, -1},
122*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{"S-1-5", 17, "", "IUSR", 0, IDMAP_SENTINEL_PID, -1, -1},
1231fcced4cSJordan Brown 	{"S-1-5", 18, "", "Local System", 0, IDMAP_WK_LOCAL_SYSTEM_GID, 0, 0},
124*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{"S-1-5", 19, "", "Local Service", 0, IDMAP_SENTINEL_PID, -1, -1},
125*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{"S-1-5", 20, "", "Network Service", 0, IDMAP_SENTINEL_PID, -1, -1},
1261fcced4cSJordan Brown 
1271fcced4cSJordan Brown 	/* S-1-5-21-<domain>	Machine-local definitions */
1281fcced4cSJordan Brown 	{NULL, 498, NULL, "Enterprise Read-only Domain Controllers", 0,
129*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	    IDMAP_SENTINEL_PID, -1, -1},
130*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{NULL, 500, NULL, "Administrator", 1, IDMAP_SENTINEL_PID, 1, -1},
131*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{NULL, 501, NULL, "Guest", 1, IDMAP_SENTINEL_PID, 1, -1},
132*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{NULL, 502, NULL, "KRBTGT", 1, IDMAP_SENTINEL_PID, 1, -1},
133*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{NULL, 512, NULL, "Domain Admins", 0, IDMAP_SENTINEL_PID, -1, -1},
134*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{NULL, 513, NULL, "Domain Users", 0, IDMAP_SENTINEL_PID, -1, -1},
135*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{NULL, 514, NULL, "Domain Guests", 0, IDMAP_SENTINEL_PID, -1, -1},
136*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{NULL, 515, NULL, "Domain Computers", 0, IDMAP_SENTINEL_PID, -1, -1},
137*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{NULL, 516, NULL, "Domain Controllers", 0, IDMAP_SENTINEL_PID, -1, -1},
138*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{NULL, 517, NULL, "Cert Publishers", 0, IDMAP_SENTINEL_PID, -1, -1},
139*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{NULL, 518, NULL, "Schema Admins", 0, IDMAP_SENTINEL_PID, -1, -1},
140*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{NULL, 519, NULL, "Enterprise Admins", 0, IDMAP_SENTINEL_PID, -1, -1},
1411fcced4cSJordan Brown 	{NULL, 520, NULL, "Global Policy Creator Owners", 0,
142*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	    IDMAP_SENTINEL_PID, -1, -1},
143*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{NULL, 533, NULL, "RAS and IAS Servers", 0, IDMAP_SENTINEL_PID, -1, -1},
1441fcced4cSJordan Brown 
1451fcced4cSJordan Brown 	/* S-1-5-32	BUILTIN */
146*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{"S-1-5-32", 544, "BUILTIN", "Administrators", 0,
147*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	    IDMAP_SENTINEL_PID, -1, -1},
148*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{"S-1-5-32", 545, "BUILTIN", "Users", 0, IDMAP_SENTINEL_PID, -1, -1},
149*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{"S-1-5-32", 546, "BUILTIN", "Guests", 0, IDMAP_SENTINEL_PID, -1, -1},
150*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{"S-1-5-32", 547, "BUILTIN", "Power Users", 0,
151*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	    IDMAP_SENTINEL_PID, -1, -1},
1521fcced4cSJordan Brown 	{"S-1-5-32", 548, "BUILTIN", "Account Operators", 0,
153*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	    IDMAP_SENTINEL_PID, -1, -1},
1541fcced4cSJordan Brown 	{"S-1-5-32", 549, "BUILTIN", "Server Operators", 0,
155*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	    IDMAP_SENTINEL_PID, -1, -1},
1561fcced4cSJordan Brown 	{"S-1-5-32", 550, "BUILTIN", "Print Operators", 0,
157*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	    IDMAP_SENTINEL_PID, -1, -1},
1581fcced4cSJordan Brown 	{"S-1-5-32", 551, "BUILTIN", "Backup Operators", 0,
159*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	    IDMAP_SENTINEL_PID, -1, -1},
160*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{"S-1-5-32", 552, "BUILTIN", "Replicator", 0,
161*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	    IDMAP_SENTINEL_PID, -1, -1},
1621fcced4cSJordan Brown 	{"S-1-5-32", 554, "BUILTIN", "Pre-Windows 2000 Compatible Access", 0,
163*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	    IDMAP_SENTINEL_PID, -1, -1},
1641fcced4cSJordan Brown 	{"S-1-5-32", 555, "BUILTIN", "Remote Desktop Users", 0,
165*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	    IDMAP_SENTINEL_PID, -1, -1},
1661fcced4cSJordan Brown 	{"S-1-5-32", 556, "BUILTIN", "Network Configuration Operators", 0,
167*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	    IDMAP_SENTINEL_PID, -1, -1},
1681fcced4cSJordan Brown 	{"S-1-5-32", 557, "BUILTIN", "Incoming Forest Trust Builders", 0,
169*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	    IDMAP_SENTINEL_PID, -1, -1},
1701fcced4cSJordan Brown 	{"S-1-5-32", 558, "BUILTIN", "Performance Monitor Users", 0,
171*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	    IDMAP_SENTINEL_PID, -1, -1},
1721fcced4cSJordan Brown 	{"S-1-5-32", 559, "BUILTIN", "Performance Log Users", 0,
173*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	    IDMAP_SENTINEL_PID, -1, -1},
1741fcced4cSJordan Brown 	{"S-1-5-32", 560, "BUILTIN", "Windows Authorization Access Group", 0,
175*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	    IDMAP_SENTINEL_PID, -1, -1},
1761fcced4cSJordan Brown 	{"S-1-5-32", 561, "BUILTIN", "Terminal Server License Servers", 0,
177*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	    IDMAP_SENTINEL_PID, -1, -1},
1781fcced4cSJordan Brown 	{"S-1-5-32", 562, "BUILTIN", "Distributed COM Users", 0,
179*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	    IDMAP_SENTINEL_PID, -1, -1},
180*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{"S-1-5-32", 568, "BUILTIN", "IIS_IUSRS", 0,
181*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	    IDMAP_SENTINEL_PID, -1, -1},
1821fcced4cSJordan Brown 	{"S-1-5-32", 569, "BUILTIN", "Cryptographic Operators", 0,
183*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	    IDMAP_SENTINEL_PID, -1, -1},
1841fcced4cSJordan Brown 	{"S-1-5-32", 573, "BUILTIN", "Event Log Readers", 0,
185*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	    IDMAP_SENTINEL_PID, -1, -1},
1861fcced4cSJordan Brown 	{"S-1-5-32", 574, "BUILTIN", "Certificate Service DCOM Access", 0,
187*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	    IDMAP_SENTINEL_PID, -1, -1},
1881fcced4cSJordan Brown 
189*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{"S-1-5", 33, "", "Write Restricted", 0, IDMAP_SENTINEL_PID, -1, -1},
1901fcced4cSJordan Brown 
1911fcced4cSJordan Brown 	/* S-1-5-64	NT Authority */
192*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{"S-1-5-64", 10, "", "NTLM Authentication", 0,
193*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	    IDMAP_SENTINEL_PID, -1, -1},
1941fcced4cSJordan Brown 	{"S-1-5-64", 14, "", "SChannel Authentication", 0,
195*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	    IDMAP_SENTINEL_PID, -1, -1},
196*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{"S-1-5-64", 21, "", "Digest Authentication", 0,
197*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	    IDMAP_SENTINEL_PID, -1, -1},
1981fcced4cSJordan Brown 
1991fcced4cSJordan Brown 	/* S-1-5-80-a-b-c-d NT Service */
2001fcced4cSJordan Brown 
201*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{"S-1-5", 1000, "", "Other Organization", 0,
202*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	    IDMAP_SENTINEL_PID, -1, -1},
2031fcced4cSJordan Brown 
2041fcced4cSJordan Brown 	/* S-1-7 Internet$ */
2051fcced4cSJordan Brown 
2061fcced4cSJordan Brown 	/*
2071fcced4cSJordan Brown 	 * S-1-16	Mandatory Label
2081fcced4cSJordan Brown 	 * S-1-16-0	Untrusted Mandatory Level
2091fcced4cSJordan Brown 	 * S-1-16-4096	Low Mandatory Level
2101fcced4cSJordan Brown 	 * S-1-16-8192	Medium Mandatory Level
2111fcced4cSJordan Brown 	 * S-1-16-8448	Medium Plus Mandatory Level
2121fcced4cSJordan Brown 	 * S-1-16-12288	High Mandatory Level
2131fcced4cSJordan Brown 	 * S-1-16-16384	System Mandatory Level
2141fcced4cSJordan Brown 	 * S-1-16-20480	Protected Process Mandatory Level
2151fcced4cSJordan Brown 	 */
2161fcced4cSJordan Brown };
2171fcced4cSJordan Brown 
2181fcced4cSJordan Brown /*
2191fcced4cSJordan Brown  * Find a wksid entry for the specified Windows name and domain, of the
2201fcced4cSJordan Brown  * specified type.
2211fcced4cSJordan Brown  *
2221fcced4cSJordan Brown  * Ignore entries intended only for U2W use.
2231fcced4cSJordan Brown  */
2241fcced4cSJordan Brown const
2251fcced4cSJordan Brown wksids_table_t *
2261fcced4cSJordan Brown find_wksid_by_name(const char *name, const char *domain, int type)
2271fcced4cSJordan Brown {
2281fcced4cSJordan Brown 	int i;
2291fcced4cSJordan Brown 
2301fcced4cSJordan Brown 	RDLOCK_CONFIG();
2311fcced4cSJordan Brown 	int len = strlen(_idmapdstate.hostname);
2321fcced4cSJordan Brown 	char my_host_name[len + 1];
2331fcced4cSJordan Brown 	(void) strcpy(my_host_name, _idmapdstate.hostname);
2341fcced4cSJordan Brown 	UNLOCK_CONFIG();
2351fcced4cSJordan Brown 
2361fcced4cSJordan Brown 	for (i = 0; i < NELEM(wksids); i++) {
2371fcced4cSJordan Brown 		/* Check to see if this entry yields the desired type */
2381fcced4cSJordan Brown 		switch (type) {
2391fcced4cSJordan Brown 		case IDMAP_UID:
2401fcced4cSJordan Brown 			if (wksids[i].is_user == 0)
2411fcced4cSJordan Brown 				continue;
2421fcced4cSJordan Brown 			break;
2431fcced4cSJordan Brown 		case IDMAP_GID:
2441fcced4cSJordan Brown 			if (wksids[i].is_user == 1)
2451fcced4cSJordan Brown 				continue;
2461fcced4cSJordan Brown 			break;
2471fcced4cSJordan Brown 		case IDMAP_POSIXID:
2481fcced4cSJordan Brown 			break;
2491fcced4cSJordan Brown 		default:
2501fcced4cSJordan Brown 			assert(FALSE);
2511fcced4cSJordan Brown 		}
2521fcced4cSJordan Brown 
2531fcced4cSJordan Brown 		if (strcasecmp(wksids[i].winname, name) != 0)
2541fcced4cSJordan Brown 			continue;
2551fcced4cSJordan Brown 
2561fcced4cSJordan Brown 		if (!EMPTY_STRING(domain)) {
2571fcced4cSJordan Brown 			const char *dom;
2581fcced4cSJordan Brown 
2591fcced4cSJordan Brown 			if (wksids[i].domain != NULL) {
2601fcced4cSJordan Brown 				dom = wksids[i].domain;
2611fcced4cSJordan Brown 			} else {
2621fcced4cSJordan Brown 				dom = my_host_name;
2631fcced4cSJordan Brown 			}
2641fcced4cSJordan Brown 			if (strcasecmp(dom, domain) != 0)
2651fcced4cSJordan Brown 				continue;
2661fcced4cSJordan Brown 		}
2671fcced4cSJordan Brown 
2681fcced4cSJordan Brown 		/*
2691fcced4cSJordan Brown 		 * We have a Windows name, so ignore entries that are only
2701fcced4cSJordan Brown 		 * usable for mapping UNIX->Windows.  (Note:  the current
2711fcced4cSJordan Brown 		 * table does not have any such entries.)
2721fcced4cSJordan Brown 		 */
2731fcced4cSJordan Brown 		if (wksids[i].direction == IDMAP_DIRECTION_U2W)
2741fcced4cSJordan Brown 			continue;
2751fcced4cSJordan Brown 
2761fcced4cSJordan Brown 		return (&wksids[i]);
2771fcced4cSJordan Brown 	}
2781fcced4cSJordan Brown 
2791fcced4cSJordan Brown 	return (NULL);
2801fcced4cSJordan Brown }
2811fcced4cSJordan Brown 
2821fcced4cSJordan Brown /*
2831fcced4cSJordan Brown  * Find a wksid entry for the specified SID, of the specified type.
2841fcced4cSJordan Brown  *
2851fcced4cSJordan Brown  * Ignore entries intended only for U2W use.
2861fcced4cSJordan Brown  */
2871fcced4cSJordan Brown const
2881fcced4cSJordan Brown wksids_table_t *
2891fcced4cSJordan Brown find_wksid_by_sid(const char *sid, int rid, int type)
2901fcced4cSJordan Brown {
2911fcced4cSJordan Brown 	int i;
2921fcced4cSJordan Brown 
2931fcced4cSJordan Brown 	RDLOCK_CONFIG();
2941fcced4cSJordan Brown 	int len = strlen(_idmapdstate.cfg->pgcfg.machine_sid);
2951fcced4cSJordan Brown 	char my_machine_sid[len + 1];
2961fcced4cSJordan Brown 	(void) strcpy(my_machine_sid, _idmapdstate.cfg->pgcfg.machine_sid);
2971fcced4cSJordan Brown 	UNLOCK_CONFIG();
2981fcced4cSJordan Brown 
2991fcced4cSJordan Brown 	for (i = 0; i < NELEM(wksids); i++) {
3001fcced4cSJordan Brown 		int sidcmp;
3011fcced4cSJordan Brown 
3021fcced4cSJordan Brown 		/* Check to see if this entry yields the desired type */
3031fcced4cSJordan Brown 		switch (type) {
3041fcced4cSJordan Brown 		case IDMAP_UID:
3051fcced4cSJordan Brown 			if (wksids[i].is_user == 0)
3061fcced4cSJordan Brown 				continue;
3071fcced4cSJordan Brown 			break;
3081fcced4cSJordan Brown 		case IDMAP_GID:
3091fcced4cSJordan Brown 			if (wksids[i].is_user == 1)
3101fcced4cSJordan Brown 				continue;
3111fcced4cSJordan Brown 			break;
3121fcced4cSJordan Brown 		case IDMAP_POSIXID:
3131fcced4cSJordan Brown 			break;
3141fcced4cSJordan Brown 		default:
3151fcced4cSJordan Brown 			assert(FALSE);
3161fcced4cSJordan Brown 		}
3171fcced4cSJordan Brown 
3181fcced4cSJordan Brown 		if (wksids[i].sidprefix != NULL) {
3191fcced4cSJordan Brown 			sidcmp = strcasecmp(wksids[i].sidprefix, sid);
3201fcced4cSJordan Brown 		} else {
3211fcced4cSJordan Brown 			sidcmp = strcasecmp(my_machine_sid, sid);
3221fcced4cSJordan Brown 		}
3231fcced4cSJordan Brown 
3241fcced4cSJordan Brown 		if (sidcmp != 0)
3251fcced4cSJordan Brown 			continue;
3261fcced4cSJordan Brown 		if (wksids[i].rid != rid)
3271fcced4cSJordan Brown 			continue;
3281fcced4cSJordan Brown 
3291fcced4cSJordan Brown 		/*
3301fcced4cSJordan Brown 		 * We have a SID, so ignore entries that are only usable
3311fcced4cSJordan Brown 		 * for mapping UNIX->Windows.  (Note:  the current table
3321fcced4cSJordan Brown 		 * does not have any such entries.)
3331fcced4cSJordan Brown 		 */
3341fcced4cSJordan Brown 		if (wksids[i].direction == IDMAP_DIRECTION_U2W)
3351fcced4cSJordan Brown 			continue;
3361fcced4cSJordan Brown 
3371fcced4cSJordan Brown 		return (&wksids[i]);
3381fcced4cSJordan Brown 	}
3391fcced4cSJordan Brown 
3401fcced4cSJordan Brown 	return (NULL);
3411fcced4cSJordan Brown }
3421fcced4cSJordan Brown 
3431fcced4cSJordan Brown /*
3441fcced4cSJordan Brown  * Find a wksid entry for the specified pid, of the specified type.
3451fcced4cSJordan Brown  * Ignore entries that do not specify U2W mappings.
3461fcced4cSJordan Brown  */
3471fcced4cSJordan Brown const
3481fcced4cSJordan Brown wksids_table_t *
3491fcced4cSJordan Brown find_wksid_by_pid(uid_t pid, int is_user)
3501fcced4cSJordan Brown {
3511fcced4cSJordan Brown 	int i;
3521fcced4cSJordan Brown 
353*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	if (pid == IDMAP_SENTINEL_PID)
3541fcced4cSJordan Brown 		return (NULL);
3551fcced4cSJordan Brown 
3561fcced4cSJordan Brown 	for (i = 0; i < NELEM(wksids); i++) {
3571fcced4cSJordan Brown 		if (wksids[i].pid == pid &&
3581fcced4cSJordan Brown 		    wksids[i].is_user == is_user &&
3591fcced4cSJordan Brown 		    (wksids[i].direction == IDMAP_DIRECTION_BI ||
3601fcced4cSJordan Brown 		    wksids[i].direction == IDMAP_DIRECTION_U2W)) {
3611fcced4cSJordan Brown 			return (&wksids[i]);
3621fcced4cSJordan Brown 		}
3631fcced4cSJordan Brown 	}
3641fcced4cSJordan Brown 	return (NULL);
3651fcced4cSJordan Brown }
3661fcced4cSJordan Brown 
3671fcced4cSJordan Brown /*
3681fcced4cSJordan Brown  * It is probably a bug that both this and find_wksid_by_sid exist,
3691fcced4cSJordan Brown  * but for now the distinction is primarily that one takes {machinesid,rid}
3701fcced4cSJordan Brown  * and the other takes a full SID.
3711fcced4cSJordan Brown  */
3721fcced4cSJordan Brown const
3731fcced4cSJordan Brown wksids_table_t *
3741fcced4cSJordan Brown find_wk_by_sid(char *sid)
3751fcced4cSJordan Brown {
3761fcced4cSJordan Brown 	int i;
3771fcced4cSJordan Brown 
3781fcced4cSJordan Brown 	RDLOCK_CONFIG();
3791fcced4cSJordan Brown 	int len = strlen(_idmapdstate.cfg->pgcfg.machine_sid);
3801fcced4cSJordan Brown 	char my_machine_sid[len + 1];
3811fcced4cSJordan Brown 	(void) strcpy(my_machine_sid, _idmapdstate.cfg->pgcfg.machine_sid);
3821fcced4cSJordan Brown 	UNLOCK_CONFIG();
3831fcced4cSJordan Brown 
3841fcced4cSJordan Brown 	for (i = 0; i < NELEM(wksids); i++) {
3851fcced4cSJordan Brown 		int len;
3861fcced4cSJordan Brown 		const char *prefix;
3871fcced4cSJordan Brown 		char *p;
3881fcced4cSJordan Brown 		unsigned long rid;
3891fcced4cSJordan Brown 
3901fcced4cSJordan Brown 		if (wksids[i].sidprefix == NULL)
3911fcced4cSJordan Brown 			prefix = my_machine_sid;
3921fcced4cSJordan Brown 		else
3931fcced4cSJordan Brown 			prefix = wksids[i].sidprefix;
3941fcced4cSJordan Brown 
3951fcced4cSJordan Brown 		len = strlen(prefix);
3961fcced4cSJordan Brown 
3971fcced4cSJordan Brown 		/*
3981fcced4cSJordan Brown 		 * Check to see whether the SID we're looking for starts
3991fcced4cSJordan Brown 		 * with this prefix, then a -, then a single RID, and it's
4001fcced4cSJordan Brown 		 * the right RID.
4011fcced4cSJordan Brown 		 */
4021fcced4cSJordan Brown 		if (strncasecmp(sid, prefix, len) != 0)
4031fcced4cSJordan Brown 			continue;
4041fcced4cSJordan Brown 		if (sid[len] != '-')
4051fcced4cSJordan Brown 			continue;
4061fcced4cSJordan Brown 		rid = strtoul(sid + len + 1, &p, 10);
4071fcced4cSJordan Brown 		if (*p != '\0')
4081fcced4cSJordan Brown 			continue;
4091fcced4cSJordan Brown 
4101fcced4cSJordan Brown 		if (rid != wksids[i].rid)
4111fcced4cSJordan Brown 			continue;
4121fcced4cSJordan Brown 
4131fcced4cSJordan Brown 		return (&wksids[i]);
4141fcced4cSJordan Brown 	}
4151fcced4cSJordan Brown 	return (NULL);
4161fcced4cSJordan Brown }
417