Release alpha15.
[nivanova/samba-autobuild/.git] / source3 / lib / util_builtin.c
1 /*
2    Unix SMB/CIFS implementation.
3    Translate BUILTIN names to SIDs and vice versa
4    Copyright (C) Volker Lendecke 2005
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "includes.h"
21 #include "passdb.h"
22 #include "../libcli/security/security.h"
23
24 struct rid_name_map {
25         uint32 rid;
26         const char *name;
27 };
28
29 static const struct rid_name_map builtin_aliases[] = {
30         { BUILTIN_RID_ADMINISTRATORS,           "Administrators" },
31         { BUILTIN_RID_USERS,            "Users" },
32         { BUILTIN_RID_GUESTS,           "Guests" },
33         { BUILTIN_RID_POWER_USERS,      "Power Users" },
34         { BUILTIN_RID_ACCOUNT_OPERATORS,        "Account Operators" },
35         { BUILTIN_RID_SERVER_OPERATORS,         "Server Operators" },
36         { BUILTIN_RID_PRINT_OPERATORS,          "Print Operators" },
37         { BUILTIN_RID_BACKUP_OPERATORS,         "Backup Operators" },
38         { BUILTIN_RID_REPLICATOR,               "Replicator" },
39         { BUILTIN_RID_RAS_SERVERS,              "RAS Servers" },
40         { BUILTIN_RID_PRE_2K_ACCESS,
41                 "Pre-Windows 2000 Compatible Access" },
42         { BUILTIN_RID_REMOTE_DESKTOP_USERS,
43                 "Remote Desktop Users" },
44         { BUILTIN_RID_NETWORK_CONF_OPERATORS,
45                 "Network Configuration Operators" },
46         { BUILTIN_RID_INCOMING_FOREST_TRUST,
47                 "Incoming Forest Trust Builders" },
48         { BUILTIN_RID_PERFMON_USERS,
49                 "Performance Monitor Users" },
50         { BUILTIN_RID_PERFLOG_USERS,
51                 "Performance Log Users" },
52         { BUILTIN_RID_AUTH_ACCESS,
53                 "Windows Authorization Access Group" },
54         { BUILTIN_RID_TS_LICENSE_SERVERS,
55                 "Terminal Server License Servers" },
56         {  0, NULL}};
57
58 /*******************************************************************
59  Look up a rid in the BUILTIN domain
60  ********************************************************************/
61 bool lookup_builtin_rid(TALLOC_CTX *mem_ctx, uint32 rid, const char **name)
62 {
63         const struct rid_name_map *aliases = builtin_aliases;
64
65         while (aliases->name != NULL) {
66                 if (rid == aliases->rid) {
67                         *name = talloc_strdup(mem_ctx, aliases->name);
68                         return True;
69                 }
70                 aliases++;
71         }
72
73         return False;
74 }
75
76 /*******************************************************************
77  Look up a name in the BUILTIN domain
78  ********************************************************************/
79 bool lookup_builtin_name(const char *name, uint32 *rid)
80 {
81         const struct rid_name_map *aliases = builtin_aliases;
82
83         while (aliases->name != NULL) {
84                 if (strequal(name, aliases->name)) {
85                         *rid = aliases->rid;
86                         return True;
87                 }
88                 aliases++;
89         }
90
91         return False;
92 }
93
94 /*****************************************************************
95  Return the name of the BUILTIN domain
96 *****************************************************************/
97
98 const char *builtin_domain_name(void)
99 {
100         return "BUILTIN";
101 }
102
103 /*****************************************************************
104  Check if the SID is the builtin SID (S-1-5-32).
105 *****************************************************************/
106
107 bool sid_check_is_builtin(const struct dom_sid *sid)
108 {
109         return dom_sid_equal(sid, &global_sid_Builtin);
110 }
111
112 /*****************************************************************
113  Check if the SID is one of the builtin SIDs (S-1-5-32-a).
114 *****************************************************************/
115
116 bool sid_check_is_in_builtin(const struct dom_sid *sid)
117 {
118         struct dom_sid dom_sid;
119
120         sid_copy(&dom_sid, sid);
121         sid_split_rid(&dom_sid, NULL);
122
123         return sid_check_is_builtin(&dom_sid);
124 }