Fix some nonempty blank lines
[ira/wip.git] / source3 / passdb / 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
22 struct rid_name_map {
23         uint32 rid;
24         const char *name;
25 };
26
27 static const struct rid_name_map builtin_aliases[] = {
28         { BUILTIN_ALIAS_RID_ADMINS,             "Administrators" },
29         { BUILTIN_ALIAS_RID_USERS,              "Users" },
30         { BUILTIN_ALIAS_RID_GUESTS,             "Guests" },
31         { BUILTIN_ALIAS_RID_POWER_USERS,        "Power Users" },
32         { BUILTIN_ALIAS_RID_ACCOUNT_OPS,        "Account Operators" },
33         { BUILTIN_ALIAS_RID_SYSTEM_OPS,         "Server Operators" },
34         { BUILTIN_ALIAS_RID_PRINT_OPS,          "Print Operators" },
35         { BUILTIN_ALIAS_RID_BACKUP_OPS,         "Backup Operators" },
36         { BUILTIN_ALIAS_RID_REPLICATOR,         "Replicator" },
37         { BUILTIN_ALIAS_RID_RAS_SERVERS,        "RAS Servers" },
38         { BUILTIN_ALIAS_RID_PRE_2K_ACCESS,
39                 "Pre-Windows 2000 Compatible Access" },
40         { BUILTIN_ALIAS_RID_REMOTE_DESKTOP_USERS,
41                 "Remote Desktop Users" },
42         { BUILTIN_ALIAS_RID_NETWORK_CONF_OPERATORS,
43                 "Network Configuration Operators" },
44         { BUILTIN_ALIAS_RID_INCOMING_FOREST_TRUST,
45                 "Incoming Forest Trust Builders" },
46         { BUILTIN_ALIAS_RID_PERFMON_USERS,
47                 "Performance Monitor Users" },
48         { BUILTIN_ALIAS_RID_PERFLOG_USERS,
49                 "Performance Log Users" },
50         { BUILTIN_ALIAS_RID_AUTH_ACCESS,
51                 "Windows Authorization Access Group" },
52         { BUILTIN_ALIAS_RID_TS_LICENSE_SERVERS,
53                 "Terminal Server License Servers" },
54         {  0, NULL}};
55
56 /*******************************************************************
57  Look up a rid in the BUILTIN domain
58  ********************************************************************/
59 bool lookup_builtin_rid(TALLOC_CTX *mem_ctx, uint32 rid, const char **name)
60 {
61         const struct rid_name_map *aliases = builtin_aliases;
62
63         while (aliases->name != NULL) {
64                 if (rid == aliases->rid) {
65                         *name = talloc_strdup(mem_ctx, aliases->name);
66                         return True;
67                 }
68                 aliases++;
69         }
70
71         return False;
72 }
73
74 /*******************************************************************
75  Look up a name in the BUILTIN domain
76  ********************************************************************/
77 bool lookup_builtin_name(const char *name, uint32 *rid)
78 {
79         const struct rid_name_map *aliases = builtin_aliases;
80
81         while (aliases->name != NULL) {
82                 if (strequal(name, aliases->name)) {
83                         *rid = aliases->rid;
84                         return True;
85                 }
86                 aliases++;
87         }
88
89         return False;
90 }
91
92 /*****************************************************************
93  Return the name of the BUILTIN domain
94 *****************************************************************/  
95
96 const char *builtin_domain_name(void)
97 {
98         return "BUILTIN";
99 }
100
101 /*****************************************************************
102  Check if the SID is the builtin SID (S-1-5-32).
103 *****************************************************************/  
104
105 bool sid_check_is_builtin(const DOM_SID *sid)
106 {
107         return sid_equal(sid, &global_sid_Builtin);
108 }
109
110 /*****************************************************************
111  Check if the SID is one of the builtin SIDs (S-1-5-32-a).
112 *****************************************************************/  
113
114 bool sid_check_is_in_builtin(const DOM_SID *sid)
115 {
116         DOM_SID dom_sid;
117         uint32 rid;
118
119         sid_copy(&dom_sid, sid);
120         sid_split_rid(&dom_sid, &rid);
121         
122         return sid_check_is_builtin(&dom_sid);
123 }
124