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 /*
23148c5f43SAlan Wright * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
241fcced4cSJordan Brown */
251fcced4cSJordan Brown
261fcced4cSJordan Brown /*
271fcced4cSJordan Brown * Information about well-known (builtin) names, and functions to retrieve
281fcced4cSJordan Brown * information about them.
291fcced4cSJordan Brown */
301fcced4cSJordan Brown
311fcced4cSJordan Brown #include <assert.h>
321fcced4cSJordan Brown #include <string.h>
33*cb174861Sjoyce mcintosh #include <libuutil.h>
341fcced4cSJordan Brown #include "idmapd.h"
351fcced4cSJordan Brown
361fcced4cSJordan Brown /*
371fcced4cSJordan Brown * Table for well-known SIDs.
381fcced4cSJordan Brown *
391fcced4cSJordan Brown * Background:
401fcced4cSJordan Brown *
411fcced4cSJordan Brown * Some of the well-known principals are stored under:
421fcced4cSJordan Brown * cn=WellKnown Security Principals, cn=Configuration, dc=<forestRootDomain>
431fcced4cSJordan Brown * They belong to objectClass "foreignSecurityPrincipal". They don't have
441fcced4cSJordan Brown * "samAccountName" nor "userPrincipalName" attributes. Their names are
451fcced4cSJordan Brown * available in "cn" and "name" attributes. Some of these principals have a
461fcced4cSJordan Brown * second entry under CN=ForeignSecurityPrincipals,dc=<forestRootDomain> and
471fcced4cSJordan Brown * these duplicate entries have the stringified SID in the "name" and "cn"
481fcced4cSJordan Brown * attributes instead of the actual name.
491fcced4cSJordan Brown *
501fcced4cSJordan Brown * Those of the form S-1-5-32-X are Builtin groups and are stored in the
511fcced4cSJordan Brown * cn=builtin container (except, Power Users which is not stored in AD)
521fcced4cSJordan Brown *
531fcced4cSJordan Brown * These principals are and will remain constant. Therefore doing AD lookups
541fcced4cSJordan Brown * provides no benefit. Also, using hard-coded table (and thus avoiding AD
551fcced4cSJordan Brown * lookup) improves performance and avoids additional complexity in the
561fcced4cSJordan Brown * adutils.c code. Moreover these SIDs can be used when no Active Directory
571fcced4cSJordan Brown * is available (such as the CIFS server's "workgroup" mode).
581fcced4cSJordan Brown *
591fcced4cSJordan Brown * Notes:
601fcced4cSJordan Brown * 1. Currently we don't support localization of well-known SID names,
611fcced4cSJordan Brown * unlike Windows.
621fcced4cSJordan Brown *
631fcced4cSJordan Brown * 2. Other well-known SIDs i.e. S-1-5-<domain>-<w-k RID> are not stored
641fcced4cSJordan Brown * here. AD does have normal user/group objects for these objects and
651fcced4cSJordan Brown * can be looked up using the existing AD lookup code.
661fcced4cSJordan Brown *
671fcced4cSJordan Brown * 3. See comments above lookup_wksids_sid2pid() for more information
681fcced4cSJordan Brown * on how we lookup the wksids table.
691fcced4cSJordan Brown *
701fcced4cSJordan Brown * 4. If this table contains two entries for a particular Windows name,
711fcced4cSJordan Brown * so as to offer both UID and GID mappings, the preferred mapping (the
721fcced4cSJordan Brown * one that matches Windows usage) must be listed first. That is the
731fcced4cSJordan Brown * entry that will be used when the caller specifies IDMAP_POSIXID
741fcced4cSJordan Brown * ("don't care") as the target.
751fcced4cSJordan Brown *
761fcced4cSJordan Brown * Entries here come from KB243330, MS-LSAT, and
771fcced4cSJordan Brown * http://technet.microsoft.com/en-us/library/cc755854.aspx
781fcced4cSJordan Brown * http://technet.microsoft.com/en-us/library/cc755925.aspx
791fcced4cSJordan Brown * http://msdn.microsoft.com/en-us/library/cc980032(PROT.10).aspx
801fcced4cSJordan Brown */
811fcced4cSJordan Brown static wksids_table_t wksids[] = {
821fcced4cSJordan Brown /* S-1-0 Null Authority */
839fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {"S-1-0", 0, "", "Nobody", 1, IDMAP_SENTINEL_PID, -1, 1},
841fcced4cSJordan Brown
851fcced4cSJordan Brown /* S-1-1 World Authority */
869fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {"S-1-1", 0, "", "Everyone", 0, IDMAP_SENTINEL_PID, -1, -1},
871fcced4cSJordan Brown
881fcced4cSJordan Brown /* S-1-2 Local Authority */
899fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {"S-1-2", 0, "", "Local", 0, IDMAP_SENTINEL_PID, -1, -1},
909fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {"S-1-2", 1, "", "Console Logon", 0, IDMAP_SENTINEL_PID, -1, -1},
911fcced4cSJordan Brown
921fcced4cSJordan Brown /* S-1-3 Creator Authority */
931fcced4cSJordan Brown {"S-1-3", 0, "", "Creator Owner", 1, IDMAP_WK_CREATOR_OWNER_UID, 1, 0},
941fcced4cSJordan Brown {"S-1-3", 1, "", "Creator Group", 0, IDMAP_WK_CREATOR_GROUP_GID, 0, 0},
959fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {"S-1-3", 2, "", "Creator Owner Server", 1, IDMAP_SENTINEL_PID, -1, -1},
969fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {"S-1-3", 3, "", "Creator Group Server", 0, IDMAP_SENTINEL_PID, -1, 1},
979fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {"S-1-3", 4, "", "Owner Rights", 0, IDMAP_SENTINEL_PID, -1, -1},
981fcced4cSJordan Brown
991fcced4cSJordan Brown /* S-1-4 Non-unique Authority */
1001fcced4cSJordan Brown
1011fcced4cSJordan Brown /* S-1-5 NT Authority */
1029fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {"S-1-5", 1, "", "Dialup", 0, IDMAP_SENTINEL_PID, -1, -1},
1039fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {"S-1-5", 2, "", "Network", 0, IDMAP_SENTINEL_PID, -1, -1},
1049fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {"S-1-5", 3, "", "Batch", 0, IDMAP_SENTINEL_PID, -1, -1},
1059fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {"S-1-5", 4, "", "Interactive", 0, IDMAP_SENTINEL_PID, -1, -1},
1061fcced4cSJordan Brown /* S-1-5-5-X-Y Logon Session */
1079fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {"S-1-5", 6, "", "Service", 0, IDMAP_SENTINEL_PID, -1, -1},
1081fcced4cSJordan Brown {"S-1-5", 7, "", "Anonymous Logon", 0, GID_NOBODY, 0, 0},
1091fcced4cSJordan Brown {"S-1-5", 7, "", "Anonymous Logon", 0, UID_NOBODY, 1, 0},
1109fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {"S-1-5", 8, "", "Proxy", 0, IDMAP_SENTINEL_PID, -1, -1},
1111fcced4cSJordan Brown {"S-1-5", 9, "", "Enterprise Domain Controllers", 0,
1129fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States IDMAP_SENTINEL_PID, -1, -1},
1139fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {"S-1-5", 10, "", "Self", 0, IDMAP_SENTINEL_PID, -1, -1},
1149fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {"S-1-5", 11, "", "Authenticated Users", 0, IDMAP_SENTINEL_PID, -1, -1},
1159fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {"S-1-5", 12, "", "Restricted", 0, IDMAP_SENTINEL_PID, -1, -1},
1169fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {"S-1-5", 13, "", "Terminal Server Users", 0,
1179fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States IDMAP_SENTINEL_PID, -1, -1},
1189fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {"S-1-5", 14, "", "Remote Interactive Logon", 0,
1199fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States IDMAP_SENTINEL_PID, -1, -1},
1209fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {"S-1-5", 15, "", "This Organization", 0, IDMAP_SENTINEL_PID, -1, -1},
1219fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {"S-1-5", 17, "", "IUSR", 0, IDMAP_SENTINEL_PID, -1, -1},
1221fcced4cSJordan Brown {"S-1-5", 18, "", "Local System", 0, IDMAP_WK_LOCAL_SYSTEM_GID, 0, 0},
1239fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {"S-1-5", 19, "", "Local Service", 0, IDMAP_SENTINEL_PID, -1, -1},
1249fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {"S-1-5", 20, "", "Network Service", 0, IDMAP_SENTINEL_PID, -1, -1},
1251fcced4cSJordan Brown
1261fcced4cSJordan Brown /* S-1-5-21-<domain> Machine-local definitions */
1271fcced4cSJordan Brown {NULL, 498, NULL, "Enterprise Read-only Domain Controllers", 0,
1289fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States IDMAP_SENTINEL_PID, -1, -1},
1299fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {NULL, 500, NULL, "Administrator", 1, IDMAP_SENTINEL_PID, 1, -1},
1309fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {NULL, 501, NULL, "Guest", 1, IDMAP_SENTINEL_PID, 1, -1},
1319fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {NULL, 502, NULL, "KRBTGT", 1, IDMAP_SENTINEL_PID, 1, -1},
1329fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {NULL, 512, NULL, "Domain Admins", 0, IDMAP_SENTINEL_PID, -1, -1},
1339fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {NULL, 513, NULL, "Domain Users", 0, IDMAP_SENTINEL_PID, -1, -1},
1349fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {NULL, 514, NULL, "Domain Guests", 0, IDMAP_SENTINEL_PID, -1, -1},
1359fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {NULL, 515, NULL, "Domain Computers", 0, IDMAP_SENTINEL_PID, -1, -1},
1369fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {NULL, 516, NULL, "Domain Controllers", 0, IDMAP_SENTINEL_PID, -1, -1},
1379fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {NULL, 517, NULL, "Cert Publishers", 0, IDMAP_SENTINEL_PID, -1, -1},
1389fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {NULL, 518, NULL, "Schema Admins", 0, IDMAP_SENTINEL_PID, -1, -1},
1399fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {NULL, 519, NULL, "Enterprise Admins", 0, IDMAP_SENTINEL_PID, -1, -1},
1401fcced4cSJordan Brown {NULL, 520, NULL, "Global Policy Creator Owners", 0,
1419fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States IDMAP_SENTINEL_PID, -1, -1},
1429fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {NULL, 533, NULL, "RAS and IAS Servers", 0, IDMAP_SENTINEL_PID, -1, -1},
1431fcced4cSJordan Brown
1441fcced4cSJordan Brown /* S-1-5-32 BUILTIN */
1459fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {"S-1-5-32", 544, "BUILTIN", "Administrators", 0,
1469fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States IDMAP_SENTINEL_PID, -1, -1},
1479fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {"S-1-5-32", 545, "BUILTIN", "Users", 0, IDMAP_SENTINEL_PID, -1, -1},
1489fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {"S-1-5-32", 546, "BUILTIN", "Guests", 0, IDMAP_SENTINEL_PID, -1, -1},
1499fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {"S-1-5-32", 547, "BUILTIN", "Power Users", 0,
1509fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States IDMAP_SENTINEL_PID, -1, -1},
1511fcced4cSJordan Brown {"S-1-5-32", 548, "BUILTIN", "Account Operators", 0,
1529fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States IDMAP_SENTINEL_PID, -1, -1},
1531fcced4cSJordan Brown {"S-1-5-32", 549, "BUILTIN", "Server Operators", 0,
1549fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States IDMAP_SENTINEL_PID, -1, -1},
1551fcced4cSJordan Brown {"S-1-5-32", 550, "BUILTIN", "Print Operators", 0,
1569fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States IDMAP_SENTINEL_PID, -1, -1},
1571fcced4cSJordan Brown {"S-1-5-32", 551, "BUILTIN", "Backup Operators", 0,
1589fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States IDMAP_SENTINEL_PID, -1, -1},
1599fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {"S-1-5-32", 552, "BUILTIN", "Replicator", 0,
1609fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States IDMAP_SENTINEL_PID, -1, -1},
1611fcced4cSJordan Brown {"S-1-5-32", 554, "BUILTIN", "Pre-Windows 2000 Compatible Access", 0,
1629fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States IDMAP_SENTINEL_PID, -1, -1},
1631fcced4cSJordan Brown {"S-1-5-32", 555, "BUILTIN", "Remote Desktop Users", 0,
1649fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States IDMAP_SENTINEL_PID, -1, -1},
1651fcced4cSJordan Brown {"S-1-5-32", 556, "BUILTIN", "Network Configuration Operators", 0,
1669fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States IDMAP_SENTINEL_PID, -1, -1},
1671fcced4cSJordan Brown {"S-1-5-32", 557, "BUILTIN", "Incoming Forest Trust Builders", 0,
1689fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States IDMAP_SENTINEL_PID, -1, -1},
1691fcced4cSJordan Brown {"S-1-5-32", 558, "BUILTIN", "Performance Monitor Users", 0,
1709fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States IDMAP_SENTINEL_PID, -1, -1},
1711fcced4cSJordan Brown {"S-1-5-32", 559, "BUILTIN", "Performance Log Users", 0,
1729fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States IDMAP_SENTINEL_PID, -1, -1},
1731fcced4cSJordan Brown {"S-1-5-32", 560, "BUILTIN", "Windows Authorization Access Group", 0,
1749fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States IDMAP_SENTINEL_PID, -1, -1},
1751fcced4cSJordan Brown {"S-1-5-32", 561, "BUILTIN", "Terminal Server License Servers", 0,
1769fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States IDMAP_SENTINEL_PID, -1, -1},
1771fcced4cSJordan Brown {"S-1-5-32", 562, "BUILTIN", "Distributed COM Users", 0,
1789fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States IDMAP_SENTINEL_PID, -1, -1},
1799fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {"S-1-5-32", 568, "BUILTIN", "IIS_IUSRS", 0,
1809fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States IDMAP_SENTINEL_PID, -1, -1},
1811fcced4cSJordan Brown {"S-1-5-32", 569, "BUILTIN", "Cryptographic Operators", 0,
1829fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States IDMAP_SENTINEL_PID, -1, -1},
1831fcced4cSJordan Brown {"S-1-5-32", 573, "BUILTIN", "Event Log Readers", 0,
1849fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States IDMAP_SENTINEL_PID, -1, -1},
1851fcced4cSJordan Brown {"S-1-5-32", 574, "BUILTIN", "Certificate Service DCOM Access", 0,
1869fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States IDMAP_SENTINEL_PID, -1, -1},
1871fcced4cSJordan Brown
1889fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {"S-1-5", 33, "", "Write Restricted", 0, IDMAP_SENTINEL_PID, -1, -1},
1891fcced4cSJordan Brown
1901fcced4cSJordan Brown /* S-1-5-64 NT Authority */
1919fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {"S-1-5-64", 10, "", "NTLM Authentication", 0,
1929fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States IDMAP_SENTINEL_PID, -1, -1},
1931fcced4cSJordan Brown {"S-1-5-64", 14, "", "SChannel Authentication", 0,
1949fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States IDMAP_SENTINEL_PID, -1, -1},
1959fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {"S-1-5-64", 21, "", "Digest Authentication", 0,
1969fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States IDMAP_SENTINEL_PID, -1, -1},
1971fcced4cSJordan Brown
1981fcced4cSJordan Brown /* S-1-5-80-a-b-c-d NT Service */
1991fcced4cSJordan Brown
2009fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {"S-1-5", 1000, "", "Other Organization", 0,
2019fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States IDMAP_SENTINEL_PID, -1, -1},
2021fcced4cSJordan Brown
2031fcced4cSJordan Brown /* S-1-7 Internet$ */
2041fcced4cSJordan Brown
2051fcced4cSJordan Brown /*
2061fcced4cSJordan Brown * S-1-16 Mandatory Label
2071fcced4cSJordan Brown * S-1-16-0 Untrusted Mandatory Level
2081fcced4cSJordan Brown * S-1-16-4096 Low Mandatory Level
2091fcced4cSJordan Brown * S-1-16-8192 Medium Mandatory Level
2101fcced4cSJordan Brown * S-1-16-8448 Medium Plus Mandatory Level
2111fcced4cSJordan Brown * S-1-16-12288 High Mandatory Level
2121fcced4cSJordan Brown * S-1-16-16384 System Mandatory Level
2131fcced4cSJordan Brown * S-1-16-20480 Protected Process Mandatory Level
2141fcced4cSJordan Brown */
2151fcced4cSJordan Brown };
2161fcced4cSJordan Brown
2171fcced4cSJordan Brown /*
2181fcced4cSJordan Brown * Find a wksid entry for the specified Windows name and domain, of the
2191fcced4cSJordan Brown * specified type.
2201fcced4cSJordan Brown *
2211fcced4cSJordan Brown * Ignore entries intended only for U2W use.
2221fcced4cSJordan Brown */
2231fcced4cSJordan Brown const
2241fcced4cSJordan Brown wksids_table_t *
find_wksid_by_name(const char * name,const char * domain,idmap_id_type type)225148c5f43SAlan Wright find_wksid_by_name(const char *name, const char *domain, idmap_id_type type)
2261fcced4cSJordan Brown {
2271fcced4cSJordan Brown int i;
2281fcced4cSJordan Brown
2291fcced4cSJordan Brown RDLOCK_CONFIG();
2301fcced4cSJordan Brown int len = strlen(_idmapdstate.hostname);
2311fcced4cSJordan Brown char my_host_name[len + 1];
2321fcced4cSJordan Brown (void) strcpy(my_host_name, _idmapdstate.hostname);
2331fcced4cSJordan Brown UNLOCK_CONFIG();
2341fcced4cSJordan Brown
235*cb174861Sjoyce mcintosh for (i = 0; i < UU_NELEM(wksids); i++) {
2361fcced4cSJordan Brown /* Check to see if this entry yields the desired type */
2371fcced4cSJordan Brown switch (type) {
2381fcced4cSJordan Brown case IDMAP_UID:
2391fcced4cSJordan Brown if (wksids[i].is_user == 0)
2401fcced4cSJordan Brown continue;
2411fcced4cSJordan Brown break;
2421fcced4cSJordan Brown case IDMAP_GID:
2431fcced4cSJordan Brown if (wksids[i].is_user == 1)
2441fcced4cSJordan Brown continue;
2451fcced4cSJordan Brown break;
2461fcced4cSJordan Brown case IDMAP_POSIXID:
2471fcced4cSJordan Brown break;
2481fcced4cSJordan Brown default:
2491fcced4cSJordan Brown assert(FALSE);
2501fcced4cSJordan Brown }
2511fcced4cSJordan Brown
2521fcced4cSJordan Brown if (strcasecmp(wksids[i].winname, name) != 0)
2531fcced4cSJordan Brown continue;
2541fcced4cSJordan Brown
2551fcced4cSJordan Brown if (!EMPTY_STRING(domain)) {
2561fcced4cSJordan Brown const char *dom;
2571fcced4cSJordan Brown
2581fcced4cSJordan Brown if (wksids[i].domain != NULL) {
2591fcced4cSJordan Brown dom = wksids[i].domain;
2601fcced4cSJordan Brown } else {
2611fcced4cSJordan Brown dom = my_host_name;
2621fcced4cSJordan Brown }
2631fcced4cSJordan Brown if (strcasecmp(dom, domain) != 0)
2641fcced4cSJordan Brown continue;
2651fcced4cSJordan Brown }
2661fcced4cSJordan Brown
2671fcced4cSJordan Brown /*
2681fcced4cSJordan Brown * We have a Windows name, so ignore entries that are only
2691fcced4cSJordan Brown * usable for mapping UNIX->Windows. (Note: the current
2701fcced4cSJordan Brown * table does not have any such entries.)
2711fcced4cSJordan Brown */
2721fcced4cSJordan Brown if (wksids[i].direction == IDMAP_DIRECTION_U2W)
2731fcced4cSJordan Brown continue;
2741fcced4cSJordan Brown
2751fcced4cSJordan Brown return (&wksids[i]);
2761fcced4cSJordan Brown }
2771fcced4cSJordan Brown
2781fcced4cSJordan Brown return (NULL);
2791fcced4cSJordan Brown }
2801fcced4cSJordan Brown
2811fcced4cSJordan Brown /*
2821fcced4cSJordan Brown * Find a wksid entry for the specified SID, of the specified type.
2831fcced4cSJordan Brown *
2841fcced4cSJordan Brown * Ignore entries intended only for U2W use.
2851fcced4cSJordan Brown */
2861fcced4cSJordan Brown const
2871fcced4cSJordan Brown wksids_table_t *
find_wksid_by_sid(const char * sid,int rid,idmap_id_type type)288148c5f43SAlan Wright find_wksid_by_sid(const char *sid, int rid, idmap_id_type type)
2891fcced4cSJordan Brown {
2901fcced4cSJordan Brown int i;
2911fcced4cSJordan Brown
2921fcced4cSJordan Brown RDLOCK_CONFIG();
2931fcced4cSJordan Brown int len = strlen(_idmapdstate.cfg->pgcfg.machine_sid);
2941fcced4cSJordan Brown char my_machine_sid[len + 1];
2951fcced4cSJordan Brown (void) strcpy(my_machine_sid, _idmapdstate.cfg->pgcfg.machine_sid);
2961fcced4cSJordan Brown UNLOCK_CONFIG();
2971fcced4cSJordan Brown
298*cb174861Sjoyce mcintosh for (i = 0; i < UU_NELEM(wksids); i++) {
2991fcced4cSJordan Brown int sidcmp;
3001fcced4cSJordan Brown
3011fcced4cSJordan Brown /* Check to see if this entry yields the desired type */
3021fcced4cSJordan Brown switch (type) {
3031fcced4cSJordan Brown case IDMAP_UID:
3041fcced4cSJordan Brown if (wksids[i].is_user == 0)
3051fcced4cSJordan Brown continue;
3061fcced4cSJordan Brown break;
3071fcced4cSJordan Brown case IDMAP_GID:
3081fcced4cSJordan Brown if (wksids[i].is_user == 1)
3091fcced4cSJordan Brown continue;
3101fcced4cSJordan Brown break;
3111fcced4cSJordan Brown case IDMAP_POSIXID:
3121fcced4cSJordan Brown break;
3131fcced4cSJordan Brown default:
3141fcced4cSJordan Brown assert(FALSE);
3151fcced4cSJordan Brown }
3161fcced4cSJordan Brown
3171fcced4cSJordan Brown if (wksids[i].sidprefix != NULL) {
3181fcced4cSJordan Brown sidcmp = strcasecmp(wksids[i].sidprefix, sid);
3191fcced4cSJordan Brown } else {
3201fcced4cSJordan Brown sidcmp = strcasecmp(my_machine_sid, sid);
3211fcced4cSJordan Brown }
3221fcced4cSJordan Brown
3231fcced4cSJordan Brown if (sidcmp != 0)
3241fcced4cSJordan Brown continue;
3251fcced4cSJordan Brown if (wksids[i].rid != rid)
3261fcced4cSJordan Brown continue;
3271fcced4cSJordan Brown
3281fcced4cSJordan Brown /*
3291fcced4cSJordan Brown * We have a SID, so ignore entries that are only usable
3301fcced4cSJordan Brown * for mapping UNIX->Windows. (Note: the current table
3311fcced4cSJordan Brown * does not have any such entries.)
3321fcced4cSJordan Brown */
3331fcced4cSJordan Brown if (wksids[i].direction == IDMAP_DIRECTION_U2W)
3341fcced4cSJordan Brown continue;
3351fcced4cSJordan Brown
3361fcced4cSJordan Brown return (&wksids[i]);
3371fcced4cSJordan Brown }
3381fcced4cSJordan Brown
3391fcced4cSJordan Brown return (NULL);
3401fcced4cSJordan Brown }
3411fcced4cSJordan Brown
3421fcced4cSJordan Brown /*
3431fcced4cSJordan Brown * Find a wksid entry for the specified pid, of the specified type.
3441fcced4cSJordan Brown * Ignore entries that do not specify U2W mappings.
3451fcced4cSJordan Brown */
3461fcced4cSJordan Brown const
3471fcced4cSJordan Brown wksids_table_t *
find_wksid_by_pid(uid_t pid,int is_user)3481fcced4cSJordan Brown find_wksid_by_pid(uid_t pid, int is_user)
3491fcced4cSJordan Brown {
3501fcced4cSJordan Brown int i;
3511fcced4cSJordan Brown
3529fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (pid == IDMAP_SENTINEL_PID)
3531fcced4cSJordan Brown return (NULL);
3541fcced4cSJordan Brown
355*cb174861Sjoyce mcintosh for (i = 0; i < UU_NELEM(wksids); i++) {
3561fcced4cSJordan Brown if (wksids[i].pid == pid &&
3571fcced4cSJordan Brown wksids[i].is_user == is_user &&
3581fcced4cSJordan Brown (wksids[i].direction == IDMAP_DIRECTION_BI ||
3591fcced4cSJordan Brown wksids[i].direction == IDMAP_DIRECTION_U2W)) {
3601fcced4cSJordan Brown return (&wksids[i]);
3611fcced4cSJordan Brown }
3621fcced4cSJordan Brown }
3631fcced4cSJordan Brown return (NULL);
3641fcced4cSJordan Brown }
3651fcced4cSJordan Brown
3661fcced4cSJordan Brown /*
3671fcced4cSJordan Brown * It is probably a bug that both this and find_wksid_by_sid exist,
3681fcced4cSJordan Brown * but for now the distinction is primarily that one takes {machinesid,rid}
3691fcced4cSJordan Brown * and the other takes a full SID.
3701fcced4cSJordan Brown */
3711fcced4cSJordan Brown const
3721fcced4cSJordan Brown wksids_table_t *
find_wk_by_sid(char * sid)3731fcced4cSJordan Brown find_wk_by_sid(char *sid)
3741fcced4cSJordan Brown {
3751fcced4cSJordan Brown int i;
3761fcced4cSJordan Brown
3771fcced4cSJordan Brown RDLOCK_CONFIG();
3781fcced4cSJordan Brown int len = strlen(_idmapdstate.cfg->pgcfg.machine_sid);
3791fcced4cSJordan Brown char my_machine_sid[len + 1];
3801fcced4cSJordan Brown (void) strcpy(my_machine_sid, _idmapdstate.cfg->pgcfg.machine_sid);
3811fcced4cSJordan Brown UNLOCK_CONFIG();
3821fcced4cSJordan Brown
383*cb174861Sjoyce mcintosh for (i = 0; i < UU_NELEM(wksids); i++) {
3841fcced4cSJordan Brown int len;
3851fcced4cSJordan Brown const char *prefix;
3861fcced4cSJordan Brown char *p;
3871fcced4cSJordan Brown unsigned long rid;
3881fcced4cSJordan Brown
3891fcced4cSJordan Brown if (wksids[i].sidprefix == NULL)
3901fcced4cSJordan Brown prefix = my_machine_sid;
3911fcced4cSJordan Brown else
3921fcced4cSJordan Brown prefix = wksids[i].sidprefix;
3931fcced4cSJordan Brown
3941fcced4cSJordan Brown len = strlen(prefix);
3951fcced4cSJordan Brown
3961fcced4cSJordan Brown /*
3971fcced4cSJordan Brown * Check to see whether the SID we're looking for starts
3981fcced4cSJordan Brown * with this prefix, then a -, then a single RID, and it's
3991fcced4cSJordan Brown * the right RID.
4001fcced4cSJordan Brown */
4011fcced4cSJordan Brown if (strncasecmp(sid, prefix, len) != 0)
4021fcced4cSJordan Brown continue;
4031fcced4cSJordan Brown if (sid[len] != '-')
4041fcced4cSJordan Brown continue;
4051fcced4cSJordan Brown rid = strtoul(sid + len + 1, &p, 10);
4061fcced4cSJordan Brown if (*p != '\0')
4071fcced4cSJordan Brown continue;
4081fcced4cSJordan Brown
4091fcced4cSJordan Brown if (rid != wksids[i].rid)
4101fcced4cSJordan Brown continue;
4111fcced4cSJordan Brown
4121fcced4cSJordan Brown return (&wksids[i]);
4131fcced4cSJordan Brown }
4141fcced4cSJordan Brown return (NULL);
4151fcced4cSJordan Brown }
416