110122SJordan.Brown@Sun.COM /*
210122SJordan.Brown@Sun.COM * CDDL HEADER START
310122SJordan.Brown@Sun.COM *
410122SJordan.Brown@Sun.COM * The contents of this file are subject to the terms of the
510122SJordan.Brown@Sun.COM * Common Development and Distribution License (the "License").
610122SJordan.Brown@Sun.COM * You may not use this file except in compliance with the License.
710122SJordan.Brown@Sun.COM *
810122SJordan.Brown@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
910122SJordan.Brown@Sun.COM * or http://www.opensolaris.org/os/licensing.
1010122SJordan.Brown@Sun.COM * See the License for the specific language governing permissions
1110122SJordan.Brown@Sun.COM * and limitations under the License.
1210122SJordan.Brown@Sun.COM *
1310122SJordan.Brown@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each
1410122SJordan.Brown@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1510122SJordan.Brown@Sun.COM * If applicable, add the following below this CDDL HEADER, with the
1610122SJordan.Brown@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying
1710122SJordan.Brown@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner]
1810122SJordan.Brown@Sun.COM *
1910122SJordan.Brown@Sun.COM * CDDL HEADER END
2010122SJordan.Brown@Sun.COM */
2110122SJordan.Brown@Sun.COM
2210122SJordan.Brown@Sun.COM /*
2312508Samw@Sun.COM * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
2410122SJordan.Brown@Sun.COM */
2510122SJordan.Brown@Sun.COM
2610122SJordan.Brown@Sun.COM /*
2710122SJordan.Brown@Sun.COM * Information about well-known (builtin) names, and functions to retrieve
2810122SJordan.Brown@Sun.COM * information about them.
2910122SJordan.Brown@Sun.COM */
3010122SJordan.Brown@Sun.COM
3110122SJordan.Brown@Sun.COM #include <assert.h>
3210122SJordan.Brown@Sun.COM #include <string.h>
33*12890SJoyce.McIntosh@Sun.COM #include <libuutil.h>
3410122SJordan.Brown@Sun.COM #include "idmapd.h"
3510122SJordan.Brown@Sun.COM
3610122SJordan.Brown@Sun.COM /*
3710122SJordan.Brown@Sun.COM * Table for well-known SIDs.
3810122SJordan.Brown@Sun.COM *
3910122SJordan.Brown@Sun.COM * Background:
4010122SJordan.Brown@Sun.COM *
4110122SJordan.Brown@Sun.COM * Some of the well-known principals are stored under:
4210122SJordan.Brown@Sun.COM * cn=WellKnown Security Principals, cn=Configuration, dc=<forestRootDomain>
4310122SJordan.Brown@Sun.COM * They belong to objectClass "foreignSecurityPrincipal". They don't have
4410122SJordan.Brown@Sun.COM * "samAccountName" nor "userPrincipalName" attributes. Their names are
4510122SJordan.Brown@Sun.COM * available in "cn" and "name" attributes. Some of these principals have a
4610122SJordan.Brown@Sun.COM * second entry under CN=ForeignSecurityPrincipals,dc=<forestRootDomain> and
4710122SJordan.Brown@Sun.COM * these duplicate entries have the stringified SID in the "name" and "cn"
4810122SJordan.Brown@Sun.COM * attributes instead of the actual name.
4910122SJordan.Brown@Sun.COM *
5010122SJordan.Brown@Sun.COM * Those of the form S-1-5-32-X are Builtin groups and are stored in the
5110122SJordan.Brown@Sun.COM * cn=builtin container (except, Power Users which is not stored in AD)
5210122SJordan.Brown@Sun.COM *
5310122SJordan.Brown@Sun.COM * These principals are and will remain constant. Therefore doing AD lookups
5410122SJordan.Brown@Sun.COM * provides no benefit. Also, using hard-coded table (and thus avoiding AD
5510122SJordan.Brown@Sun.COM * lookup) improves performance and avoids additional complexity in the
5610122SJordan.Brown@Sun.COM * adutils.c code. Moreover these SIDs can be used when no Active Directory
5710122SJordan.Brown@Sun.COM * is available (such as the CIFS server's "workgroup" mode).
5810122SJordan.Brown@Sun.COM *
5910122SJordan.Brown@Sun.COM * Notes:
6010122SJordan.Brown@Sun.COM * 1. Currently we don't support localization of well-known SID names,
6110122SJordan.Brown@Sun.COM * unlike Windows.
6210122SJordan.Brown@Sun.COM *
6310122SJordan.Brown@Sun.COM * 2. Other well-known SIDs i.e. S-1-5-<domain>-<w-k RID> are not stored
6410122SJordan.Brown@Sun.COM * here. AD does have normal user/group objects for these objects and
6510122SJordan.Brown@Sun.COM * can be looked up using the existing AD lookup code.
6610122SJordan.Brown@Sun.COM *
6710122SJordan.Brown@Sun.COM * 3. See comments above lookup_wksids_sid2pid() for more information
6810122SJordan.Brown@Sun.COM * on how we lookup the wksids table.
6910122SJordan.Brown@Sun.COM *
7010122SJordan.Brown@Sun.COM * 4. If this table contains two entries for a particular Windows name,
7110122SJordan.Brown@Sun.COM * so as to offer both UID and GID mappings, the preferred mapping (the
7210122SJordan.Brown@Sun.COM * one that matches Windows usage) must be listed first. That is the
7310122SJordan.Brown@Sun.COM * entry that will be used when the caller specifies IDMAP_POSIXID
7410122SJordan.Brown@Sun.COM * ("don't care") as the target.
7510122SJordan.Brown@Sun.COM *
7610122SJordan.Brown@Sun.COM * Entries here come from KB243330, MS-LSAT, and
7710122SJordan.Brown@Sun.COM * http://technet.microsoft.com/en-us/library/cc755854.aspx
7810122SJordan.Brown@Sun.COM * http://technet.microsoft.com/en-us/library/cc755925.aspx
7910122SJordan.Brown@Sun.COM * http://msdn.microsoft.com/en-us/library/cc980032(PROT.10).aspx
8010122SJordan.Brown@Sun.COM */
8110122SJordan.Brown@Sun.COM static wksids_table_t wksids[] = {
8210122SJordan.Brown@Sun.COM /* S-1-0 Null Authority */
8311963SAfshin.Ardakani@Sun.COM {"S-1-0", 0, "", "Nobody", 1, IDMAP_SENTINEL_PID, -1, 1},
8410122SJordan.Brown@Sun.COM
8510122SJordan.Brown@Sun.COM /* S-1-1 World Authority */
8611963SAfshin.Ardakani@Sun.COM {"S-1-1", 0, "", "Everyone", 0, IDMAP_SENTINEL_PID, -1, -1},
8710122SJordan.Brown@Sun.COM
8810122SJordan.Brown@Sun.COM /* S-1-2 Local Authority */
8911963SAfshin.Ardakani@Sun.COM {"S-1-2", 0, "", "Local", 0, IDMAP_SENTINEL_PID, -1, -1},
9011963SAfshin.Ardakani@Sun.COM {"S-1-2", 1, "", "Console Logon", 0, IDMAP_SENTINEL_PID, -1, -1},
9110122SJordan.Brown@Sun.COM
9210122SJordan.Brown@Sun.COM /* S-1-3 Creator Authority */
9310122SJordan.Brown@Sun.COM {"S-1-3", 0, "", "Creator Owner", 1, IDMAP_WK_CREATOR_OWNER_UID, 1, 0},
9410122SJordan.Brown@Sun.COM {"S-1-3", 1, "", "Creator Group", 0, IDMAP_WK_CREATOR_GROUP_GID, 0, 0},
9511963SAfshin.Ardakani@Sun.COM {"S-1-3", 2, "", "Creator Owner Server", 1, IDMAP_SENTINEL_PID, -1, -1},
9611963SAfshin.Ardakani@Sun.COM {"S-1-3", 3, "", "Creator Group Server", 0, IDMAP_SENTINEL_PID, -1, 1},
9711963SAfshin.Ardakani@Sun.COM {"S-1-3", 4, "", "Owner Rights", 0, IDMAP_SENTINEL_PID, -1, -1},
9810122SJordan.Brown@Sun.COM
9910122SJordan.Brown@Sun.COM /* S-1-4 Non-unique Authority */
10010122SJordan.Brown@Sun.COM
10110122SJordan.Brown@Sun.COM /* S-1-5 NT Authority */
10211963SAfshin.Ardakani@Sun.COM {"S-1-5", 1, "", "Dialup", 0, IDMAP_SENTINEL_PID, -1, -1},
10311963SAfshin.Ardakani@Sun.COM {"S-1-5", 2, "", "Network", 0, IDMAP_SENTINEL_PID, -1, -1},
10411963SAfshin.Ardakani@Sun.COM {"S-1-5", 3, "", "Batch", 0, IDMAP_SENTINEL_PID, -1, -1},
10511963SAfshin.Ardakani@Sun.COM {"S-1-5", 4, "", "Interactive", 0, IDMAP_SENTINEL_PID, -1, -1},
10610122SJordan.Brown@Sun.COM /* S-1-5-5-X-Y Logon Session */
10711963SAfshin.Ardakani@Sun.COM {"S-1-5", 6, "", "Service", 0, IDMAP_SENTINEL_PID, -1, -1},
10810122SJordan.Brown@Sun.COM {"S-1-5", 7, "", "Anonymous Logon", 0, GID_NOBODY, 0, 0},
10910122SJordan.Brown@Sun.COM {"S-1-5", 7, "", "Anonymous Logon", 0, UID_NOBODY, 1, 0},
11011963SAfshin.Ardakani@Sun.COM {"S-1-5", 8, "", "Proxy", 0, IDMAP_SENTINEL_PID, -1, -1},
11110122SJordan.Brown@Sun.COM {"S-1-5", 9, "", "Enterprise Domain Controllers", 0,
11211963SAfshin.Ardakani@Sun.COM IDMAP_SENTINEL_PID, -1, -1},
11311963SAfshin.Ardakani@Sun.COM {"S-1-5", 10, "", "Self", 0, IDMAP_SENTINEL_PID, -1, -1},
11411963SAfshin.Ardakani@Sun.COM {"S-1-5", 11, "", "Authenticated Users", 0, IDMAP_SENTINEL_PID, -1, -1},
11511963SAfshin.Ardakani@Sun.COM {"S-1-5", 12, "", "Restricted", 0, IDMAP_SENTINEL_PID, -1, -1},
11611963SAfshin.Ardakani@Sun.COM {"S-1-5", 13, "", "Terminal Server Users", 0,
11711963SAfshin.Ardakani@Sun.COM IDMAP_SENTINEL_PID, -1, -1},
11811963SAfshin.Ardakani@Sun.COM {"S-1-5", 14, "", "Remote Interactive Logon", 0,
11911963SAfshin.Ardakani@Sun.COM IDMAP_SENTINEL_PID, -1, -1},
12011963SAfshin.Ardakani@Sun.COM {"S-1-5", 15, "", "This Organization", 0, IDMAP_SENTINEL_PID, -1, -1},
12111963SAfshin.Ardakani@Sun.COM {"S-1-5", 17, "", "IUSR", 0, IDMAP_SENTINEL_PID, -1, -1},
12210122SJordan.Brown@Sun.COM {"S-1-5", 18, "", "Local System", 0, IDMAP_WK_LOCAL_SYSTEM_GID, 0, 0},
12311963SAfshin.Ardakani@Sun.COM {"S-1-5", 19, "", "Local Service", 0, IDMAP_SENTINEL_PID, -1, -1},
12411963SAfshin.Ardakani@Sun.COM {"S-1-5", 20, "", "Network Service", 0, IDMAP_SENTINEL_PID, -1, -1},
12510122SJordan.Brown@Sun.COM
12610122SJordan.Brown@Sun.COM /* S-1-5-21-<domain> Machine-local definitions */
12710122SJordan.Brown@Sun.COM {NULL, 498, NULL, "Enterprise Read-only Domain Controllers", 0,
12811963SAfshin.Ardakani@Sun.COM IDMAP_SENTINEL_PID, -1, -1},
12911963SAfshin.Ardakani@Sun.COM {NULL, 500, NULL, "Administrator", 1, IDMAP_SENTINEL_PID, 1, -1},
13011963SAfshin.Ardakani@Sun.COM {NULL, 501, NULL, "Guest", 1, IDMAP_SENTINEL_PID, 1, -1},
13111963SAfshin.Ardakani@Sun.COM {NULL, 502, NULL, "KRBTGT", 1, IDMAP_SENTINEL_PID, 1, -1},
13211963SAfshin.Ardakani@Sun.COM {NULL, 512, NULL, "Domain Admins", 0, IDMAP_SENTINEL_PID, -1, -1},
13311963SAfshin.Ardakani@Sun.COM {NULL, 513, NULL, "Domain Users", 0, IDMAP_SENTINEL_PID, -1, -1},
13411963SAfshin.Ardakani@Sun.COM {NULL, 514, NULL, "Domain Guests", 0, IDMAP_SENTINEL_PID, -1, -1},
13511963SAfshin.Ardakani@Sun.COM {NULL, 515, NULL, "Domain Computers", 0, IDMAP_SENTINEL_PID, -1, -1},
13611963SAfshin.Ardakani@Sun.COM {NULL, 516, NULL, "Domain Controllers", 0, IDMAP_SENTINEL_PID, -1, -1},
13711963SAfshin.Ardakani@Sun.COM {NULL, 517, NULL, "Cert Publishers", 0, IDMAP_SENTINEL_PID, -1, -1},
13811963SAfshin.Ardakani@Sun.COM {NULL, 518, NULL, "Schema Admins", 0, IDMAP_SENTINEL_PID, -1, -1},
13911963SAfshin.Ardakani@Sun.COM {NULL, 519, NULL, "Enterprise Admins", 0, IDMAP_SENTINEL_PID, -1, -1},
14010122SJordan.Brown@Sun.COM {NULL, 520, NULL, "Global Policy Creator Owners", 0,
14111963SAfshin.Ardakani@Sun.COM IDMAP_SENTINEL_PID, -1, -1},
14211963SAfshin.Ardakani@Sun.COM {NULL, 533, NULL, "RAS and IAS Servers", 0, IDMAP_SENTINEL_PID, -1, -1},
14310122SJordan.Brown@Sun.COM
14410122SJordan.Brown@Sun.COM /* S-1-5-32 BUILTIN */
14511963SAfshin.Ardakani@Sun.COM {"S-1-5-32", 544, "BUILTIN", "Administrators", 0,
14611963SAfshin.Ardakani@Sun.COM IDMAP_SENTINEL_PID, -1, -1},
14711963SAfshin.Ardakani@Sun.COM {"S-1-5-32", 545, "BUILTIN", "Users", 0, IDMAP_SENTINEL_PID, -1, -1},
14811963SAfshin.Ardakani@Sun.COM {"S-1-5-32", 546, "BUILTIN", "Guests", 0, IDMAP_SENTINEL_PID, -1, -1},
14911963SAfshin.Ardakani@Sun.COM {"S-1-5-32", 547, "BUILTIN", "Power Users", 0,
15011963SAfshin.Ardakani@Sun.COM IDMAP_SENTINEL_PID, -1, -1},
15110122SJordan.Brown@Sun.COM {"S-1-5-32", 548, "BUILTIN", "Account Operators", 0,
15211963SAfshin.Ardakani@Sun.COM IDMAP_SENTINEL_PID, -1, -1},
15310122SJordan.Brown@Sun.COM {"S-1-5-32", 549, "BUILTIN", "Server Operators", 0,
15411963SAfshin.Ardakani@Sun.COM IDMAP_SENTINEL_PID, -1, -1},
15510122SJordan.Brown@Sun.COM {"S-1-5-32", 550, "BUILTIN", "Print Operators", 0,
15611963SAfshin.Ardakani@Sun.COM IDMAP_SENTINEL_PID, -1, -1},
15710122SJordan.Brown@Sun.COM {"S-1-5-32", 551, "BUILTIN", "Backup Operators", 0,
15811963SAfshin.Ardakani@Sun.COM IDMAP_SENTINEL_PID, -1, -1},
15911963SAfshin.Ardakani@Sun.COM {"S-1-5-32", 552, "BUILTIN", "Replicator", 0,
16011963SAfshin.Ardakani@Sun.COM IDMAP_SENTINEL_PID, -1, -1},
16110122SJordan.Brown@Sun.COM {"S-1-5-32", 554, "BUILTIN", "Pre-Windows 2000 Compatible Access", 0,
16211963SAfshin.Ardakani@Sun.COM IDMAP_SENTINEL_PID, -1, -1},
16310122SJordan.Brown@Sun.COM {"S-1-5-32", 555, "BUILTIN", "Remote Desktop Users", 0,
16411963SAfshin.Ardakani@Sun.COM IDMAP_SENTINEL_PID, -1, -1},
16510122SJordan.Brown@Sun.COM {"S-1-5-32", 556, "BUILTIN", "Network Configuration Operators", 0,
16611963SAfshin.Ardakani@Sun.COM IDMAP_SENTINEL_PID, -1, -1},
16710122SJordan.Brown@Sun.COM {"S-1-5-32", 557, "BUILTIN", "Incoming Forest Trust Builders", 0,
16811963SAfshin.Ardakani@Sun.COM IDMAP_SENTINEL_PID, -1, -1},
16910122SJordan.Brown@Sun.COM {"S-1-5-32", 558, "BUILTIN", "Performance Monitor Users", 0,
17011963SAfshin.Ardakani@Sun.COM IDMAP_SENTINEL_PID, -1, -1},
17110122SJordan.Brown@Sun.COM {"S-1-5-32", 559, "BUILTIN", "Performance Log Users", 0,
17211963SAfshin.Ardakani@Sun.COM IDMAP_SENTINEL_PID, -1, -1},
17310122SJordan.Brown@Sun.COM {"S-1-5-32", 560, "BUILTIN", "Windows Authorization Access Group", 0,
17411963SAfshin.Ardakani@Sun.COM IDMAP_SENTINEL_PID, -1, -1},
17510122SJordan.Brown@Sun.COM {"S-1-5-32", 561, "BUILTIN", "Terminal Server License Servers", 0,
17611963SAfshin.Ardakani@Sun.COM IDMAP_SENTINEL_PID, -1, -1},
17710122SJordan.Brown@Sun.COM {"S-1-5-32", 562, "BUILTIN", "Distributed COM Users", 0,
17811963SAfshin.Ardakani@Sun.COM IDMAP_SENTINEL_PID, -1, -1},
17911963SAfshin.Ardakani@Sun.COM {"S-1-5-32", 568, "BUILTIN", "IIS_IUSRS", 0,
18011963SAfshin.Ardakani@Sun.COM IDMAP_SENTINEL_PID, -1, -1},
18110122SJordan.Brown@Sun.COM {"S-1-5-32", 569, "BUILTIN", "Cryptographic Operators", 0,
18211963SAfshin.Ardakani@Sun.COM IDMAP_SENTINEL_PID, -1, -1},
18310122SJordan.Brown@Sun.COM {"S-1-5-32", 573, "BUILTIN", "Event Log Readers", 0,
18411963SAfshin.Ardakani@Sun.COM IDMAP_SENTINEL_PID, -1, -1},
18510122SJordan.Brown@Sun.COM {"S-1-5-32", 574, "BUILTIN", "Certificate Service DCOM Access", 0,
18611963SAfshin.Ardakani@Sun.COM IDMAP_SENTINEL_PID, -1, -1},
18710122SJordan.Brown@Sun.COM
18811963SAfshin.Ardakani@Sun.COM {"S-1-5", 33, "", "Write Restricted", 0, IDMAP_SENTINEL_PID, -1, -1},
18910122SJordan.Brown@Sun.COM
19010122SJordan.Brown@Sun.COM /* S-1-5-64 NT Authority */
19111963SAfshin.Ardakani@Sun.COM {"S-1-5-64", 10, "", "NTLM Authentication", 0,
19211963SAfshin.Ardakani@Sun.COM IDMAP_SENTINEL_PID, -1, -1},
19310122SJordan.Brown@Sun.COM {"S-1-5-64", 14, "", "SChannel Authentication", 0,
19411963SAfshin.Ardakani@Sun.COM IDMAP_SENTINEL_PID, -1, -1},
19511963SAfshin.Ardakani@Sun.COM {"S-1-5-64", 21, "", "Digest Authentication", 0,
19611963SAfshin.Ardakani@Sun.COM IDMAP_SENTINEL_PID, -1, -1},
19710122SJordan.Brown@Sun.COM
19810122SJordan.Brown@Sun.COM /* S-1-5-80-a-b-c-d NT Service */
19910122SJordan.Brown@Sun.COM
20011963SAfshin.Ardakani@Sun.COM {"S-1-5", 1000, "", "Other Organization", 0,
20111963SAfshin.Ardakani@Sun.COM IDMAP_SENTINEL_PID, -1, -1},
20210122SJordan.Brown@Sun.COM
20310122SJordan.Brown@Sun.COM /* S-1-7 Internet$ */
20410122SJordan.Brown@Sun.COM
20510122SJordan.Brown@Sun.COM /*
20610122SJordan.Brown@Sun.COM * S-1-16 Mandatory Label
20710122SJordan.Brown@Sun.COM * S-1-16-0 Untrusted Mandatory Level
20810122SJordan.Brown@Sun.COM * S-1-16-4096 Low Mandatory Level
20910122SJordan.Brown@Sun.COM * S-1-16-8192 Medium Mandatory Level
21010122SJordan.Brown@Sun.COM * S-1-16-8448 Medium Plus Mandatory Level
21110122SJordan.Brown@Sun.COM * S-1-16-12288 High Mandatory Level
21210122SJordan.Brown@Sun.COM * S-1-16-16384 System Mandatory Level
21310122SJordan.Brown@Sun.COM * S-1-16-20480 Protected Process Mandatory Level
21410122SJordan.Brown@Sun.COM */
21510122SJordan.Brown@Sun.COM };
21610122SJordan.Brown@Sun.COM
21710122SJordan.Brown@Sun.COM /*
21810122SJordan.Brown@Sun.COM * Find a wksid entry for the specified Windows name and domain, of the
21910122SJordan.Brown@Sun.COM * specified type.
22010122SJordan.Brown@Sun.COM *
22110122SJordan.Brown@Sun.COM * Ignore entries intended only for U2W use.
22210122SJordan.Brown@Sun.COM */
22310122SJordan.Brown@Sun.COM const
22410122SJordan.Brown@Sun.COM wksids_table_t *
find_wksid_by_name(const char * name,const char * domain,idmap_id_type type)22512508Samw@Sun.COM find_wksid_by_name(const char *name, const char *domain, idmap_id_type type)
22610122SJordan.Brown@Sun.COM {
22710122SJordan.Brown@Sun.COM int i;
22810122SJordan.Brown@Sun.COM
22910122SJordan.Brown@Sun.COM RDLOCK_CONFIG();
23010122SJordan.Brown@Sun.COM int len = strlen(_idmapdstate.hostname);
23110122SJordan.Brown@Sun.COM char my_host_name[len + 1];
23210122SJordan.Brown@Sun.COM (void) strcpy(my_host_name, _idmapdstate.hostname);
23310122SJordan.Brown@Sun.COM UNLOCK_CONFIG();
23410122SJordan.Brown@Sun.COM
235*12890SJoyce.McIntosh@Sun.COM for (i = 0; i < UU_NELEM(wksids); i++) {
23610122SJordan.Brown@Sun.COM /* Check to see if this entry yields the desired type */
23710122SJordan.Brown@Sun.COM switch (type) {
23810122SJordan.Brown@Sun.COM case IDMAP_UID:
23910122SJordan.Brown@Sun.COM if (wksids[i].is_user == 0)
24010122SJordan.Brown@Sun.COM continue;
24110122SJordan.Brown@Sun.COM break;
24210122SJordan.Brown@Sun.COM case IDMAP_GID:
24310122SJordan.Brown@Sun.COM if (wksids[i].is_user == 1)
24410122SJordan.Brown@Sun.COM continue;
24510122SJordan.Brown@Sun.COM break;
24610122SJordan.Brown@Sun.COM case IDMAP_POSIXID:
24710122SJordan.Brown@Sun.COM break;
24810122SJordan.Brown@Sun.COM default:
24910122SJordan.Brown@Sun.COM assert(FALSE);
25010122SJordan.Brown@Sun.COM }
25110122SJordan.Brown@Sun.COM
25210122SJordan.Brown@Sun.COM if (strcasecmp(wksids[i].winname, name) != 0)
25310122SJordan.Brown@Sun.COM continue;
25410122SJordan.Brown@Sun.COM
25510122SJordan.Brown@Sun.COM if (!EMPTY_STRING(domain)) {
25610122SJordan.Brown@Sun.COM const char *dom;
25710122SJordan.Brown@Sun.COM
25810122SJordan.Brown@Sun.COM if (wksids[i].domain != NULL) {
25910122SJordan.Brown@Sun.COM dom = wksids[i].domain;
26010122SJordan.Brown@Sun.COM } else {
26110122SJordan.Brown@Sun.COM dom = my_host_name;
26210122SJordan.Brown@Sun.COM }
26310122SJordan.Brown@Sun.COM if (strcasecmp(dom, domain) != 0)
26410122SJordan.Brown@Sun.COM continue;
26510122SJordan.Brown@Sun.COM }
26610122SJordan.Brown@Sun.COM
26710122SJordan.Brown@Sun.COM /*
26810122SJordan.Brown@Sun.COM * We have a Windows name, so ignore entries that are only
26910122SJordan.Brown@Sun.COM * usable for mapping UNIX->Windows. (Note: the current
27010122SJordan.Brown@Sun.COM * table does not have any such entries.)
27110122SJordan.Brown@Sun.COM */
27210122SJordan.Brown@Sun.COM if (wksids[i].direction == IDMAP_DIRECTION_U2W)
27310122SJordan.Brown@Sun.COM continue;
27410122SJordan.Brown@Sun.COM
27510122SJordan.Brown@Sun.COM return (&wksids[i]);
27610122SJordan.Brown@Sun.COM }
27710122SJordan.Brown@Sun.COM
27810122SJordan.Brown@Sun.COM return (NULL);
27910122SJordan.Brown@Sun.COM }
28010122SJordan.Brown@Sun.COM
28110122SJordan.Brown@Sun.COM /*
28210122SJordan.Brown@Sun.COM * Find a wksid entry for the specified SID, of the specified type.
28310122SJordan.Brown@Sun.COM *
28410122SJordan.Brown@Sun.COM * Ignore entries intended only for U2W use.
28510122SJordan.Brown@Sun.COM */
28610122SJordan.Brown@Sun.COM const
28710122SJordan.Brown@Sun.COM wksids_table_t *
find_wksid_by_sid(const char * sid,int rid,idmap_id_type type)28812508Samw@Sun.COM find_wksid_by_sid(const char *sid, int rid, idmap_id_type type)
28910122SJordan.Brown@Sun.COM {
29010122SJordan.Brown@Sun.COM int i;
29110122SJordan.Brown@Sun.COM
29210122SJordan.Brown@Sun.COM RDLOCK_CONFIG();
29310122SJordan.Brown@Sun.COM int len = strlen(_idmapdstate.cfg->pgcfg.machine_sid);
29410122SJordan.Brown@Sun.COM char my_machine_sid[len + 1];
29510122SJordan.Brown@Sun.COM (void) strcpy(my_machine_sid, _idmapdstate.cfg->pgcfg.machine_sid);
29610122SJordan.Brown@Sun.COM UNLOCK_CONFIG();
29710122SJordan.Brown@Sun.COM
298*12890SJoyce.McIntosh@Sun.COM for (i = 0; i < UU_NELEM(wksids); i++) {
29910122SJordan.Brown@Sun.COM int sidcmp;
30010122SJordan.Brown@Sun.COM
30110122SJordan.Brown@Sun.COM /* Check to see if this entry yields the desired type */
30210122SJordan.Brown@Sun.COM switch (type) {
30310122SJordan.Brown@Sun.COM case IDMAP_UID:
30410122SJordan.Brown@Sun.COM if (wksids[i].is_user == 0)
30510122SJordan.Brown@Sun.COM continue;
30610122SJordan.Brown@Sun.COM break;
30710122SJordan.Brown@Sun.COM case IDMAP_GID:
30810122SJordan.Brown@Sun.COM if (wksids[i].is_user == 1)
30910122SJordan.Brown@Sun.COM continue;
31010122SJordan.Brown@Sun.COM break;
31110122SJordan.Brown@Sun.COM case IDMAP_POSIXID:
31210122SJordan.Brown@Sun.COM break;
31310122SJordan.Brown@Sun.COM default:
31410122SJordan.Brown@Sun.COM assert(FALSE);
31510122SJordan.Brown@Sun.COM }
31610122SJordan.Brown@Sun.COM
31710122SJordan.Brown@Sun.COM if (wksids[i].sidprefix != NULL) {
31810122SJordan.Brown@Sun.COM sidcmp = strcasecmp(wksids[i].sidprefix, sid);
31910122SJordan.Brown@Sun.COM } else {
32010122SJordan.Brown@Sun.COM sidcmp = strcasecmp(my_machine_sid, sid);
32110122SJordan.Brown@Sun.COM }
32210122SJordan.Brown@Sun.COM
32310122SJordan.Brown@Sun.COM if (sidcmp != 0)
32410122SJordan.Brown@Sun.COM continue;
32510122SJordan.Brown@Sun.COM if (wksids[i].rid != rid)
32610122SJordan.Brown@Sun.COM continue;
32710122SJordan.Brown@Sun.COM
32810122SJordan.Brown@Sun.COM /*
32910122SJordan.Brown@Sun.COM * We have a SID, so ignore entries that are only usable
33010122SJordan.Brown@Sun.COM * for mapping UNIX->Windows. (Note: the current table
33110122SJordan.Brown@Sun.COM * does not have any such entries.)
33210122SJordan.Brown@Sun.COM */
33310122SJordan.Brown@Sun.COM if (wksids[i].direction == IDMAP_DIRECTION_U2W)
33410122SJordan.Brown@Sun.COM continue;
33510122SJordan.Brown@Sun.COM
33610122SJordan.Brown@Sun.COM return (&wksids[i]);
33710122SJordan.Brown@Sun.COM }
33810122SJordan.Brown@Sun.COM
33910122SJordan.Brown@Sun.COM return (NULL);
34010122SJordan.Brown@Sun.COM }
34110122SJordan.Brown@Sun.COM
34210122SJordan.Brown@Sun.COM /*
34310122SJordan.Brown@Sun.COM * Find a wksid entry for the specified pid, of the specified type.
34410122SJordan.Brown@Sun.COM * Ignore entries that do not specify U2W mappings.
34510122SJordan.Brown@Sun.COM */
34610122SJordan.Brown@Sun.COM const
34710122SJordan.Brown@Sun.COM wksids_table_t *
find_wksid_by_pid(uid_t pid,int is_user)34810122SJordan.Brown@Sun.COM find_wksid_by_pid(uid_t pid, int is_user)
34910122SJordan.Brown@Sun.COM {
35010122SJordan.Brown@Sun.COM int i;
35110122SJordan.Brown@Sun.COM
35211963SAfshin.Ardakani@Sun.COM if (pid == IDMAP_SENTINEL_PID)
35310122SJordan.Brown@Sun.COM return (NULL);
35410122SJordan.Brown@Sun.COM
355*12890SJoyce.McIntosh@Sun.COM for (i = 0; i < UU_NELEM(wksids); i++) {
35610122SJordan.Brown@Sun.COM if (wksids[i].pid == pid &&
35710122SJordan.Brown@Sun.COM wksids[i].is_user == is_user &&
35810122SJordan.Brown@Sun.COM (wksids[i].direction == IDMAP_DIRECTION_BI ||
35910122SJordan.Brown@Sun.COM wksids[i].direction == IDMAP_DIRECTION_U2W)) {
36010122SJordan.Brown@Sun.COM return (&wksids[i]);
36110122SJordan.Brown@Sun.COM }
36210122SJordan.Brown@Sun.COM }
36310122SJordan.Brown@Sun.COM return (NULL);
36410122SJordan.Brown@Sun.COM }
36510122SJordan.Brown@Sun.COM
36610122SJordan.Brown@Sun.COM /*
36710122SJordan.Brown@Sun.COM * It is probably a bug that both this and find_wksid_by_sid exist,
36810122SJordan.Brown@Sun.COM * but for now the distinction is primarily that one takes {machinesid,rid}
36910122SJordan.Brown@Sun.COM * and the other takes a full SID.
37010122SJordan.Brown@Sun.COM */
37110122SJordan.Brown@Sun.COM const
37210122SJordan.Brown@Sun.COM wksids_table_t *
find_wk_by_sid(char * sid)37310122SJordan.Brown@Sun.COM find_wk_by_sid(char *sid)
37410122SJordan.Brown@Sun.COM {
37510122SJordan.Brown@Sun.COM int i;
37610122SJordan.Brown@Sun.COM
37710122SJordan.Brown@Sun.COM RDLOCK_CONFIG();
37810122SJordan.Brown@Sun.COM int len = strlen(_idmapdstate.cfg->pgcfg.machine_sid);
37910122SJordan.Brown@Sun.COM char my_machine_sid[len + 1];
38010122SJordan.Brown@Sun.COM (void) strcpy(my_machine_sid, _idmapdstate.cfg->pgcfg.machine_sid);
38110122SJordan.Brown@Sun.COM UNLOCK_CONFIG();
38210122SJordan.Brown@Sun.COM
383*12890SJoyce.McIntosh@Sun.COM for (i = 0; i < UU_NELEM(wksids); i++) {
38410122SJordan.Brown@Sun.COM int len;
38510122SJordan.Brown@Sun.COM const char *prefix;
38610122SJordan.Brown@Sun.COM char *p;
38710122SJordan.Brown@Sun.COM unsigned long rid;
38810122SJordan.Brown@Sun.COM
38910122SJordan.Brown@Sun.COM if (wksids[i].sidprefix == NULL)
39010122SJordan.Brown@Sun.COM prefix = my_machine_sid;
39110122SJordan.Brown@Sun.COM else
39210122SJordan.Brown@Sun.COM prefix = wksids[i].sidprefix;
39310122SJordan.Brown@Sun.COM
39410122SJordan.Brown@Sun.COM len = strlen(prefix);
39510122SJordan.Brown@Sun.COM
39610122SJordan.Brown@Sun.COM /*
39710122SJordan.Brown@Sun.COM * Check to see whether the SID we're looking for starts
39810122SJordan.Brown@Sun.COM * with this prefix, then a -, then a single RID, and it's
39910122SJordan.Brown@Sun.COM * the right RID.
40010122SJordan.Brown@Sun.COM */
40110122SJordan.Brown@Sun.COM if (strncasecmp(sid, prefix, len) != 0)
40210122SJordan.Brown@Sun.COM continue;
40310122SJordan.Brown@Sun.COM if (sid[len] != '-')
40410122SJordan.Brown@Sun.COM continue;
40510122SJordan.Brown@Sun.COM rid = strtoul(sid + len + 1, &p, 10);
40610122SJordan.Brown@Sun.COM if (*p != '\0')
40710122SJordan.Brown@Sun.COM continue;
40810122SJordan.Brown@Sun.COM
40910122SJordan.Brown@Sun.COM if (rid != wksids[i].rid)
41010122SJordan.Brown@Sun.COM continue;
41110122SJordan.Brown@Sun.COM
41210122SJordan.Brown@Sun.COM return (&wksids[i]);
41310122SJordan.Brown@Sun.COM }
41410122SJordan.Brown@Sun.COM return (NULL);
41510122SJordan.Brown@Sun.COM }
416