00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "includes.h"
00025
00026 struct rid_name_map {
00027 uint32 rid;
00028 const char *name;
00029 };
00030
00031 struct sid_name_map_info
00032 {
00033 const DOM_SID *sid;
00034 const char *name;
00035 const struct rid_name_map *known_users;
00036 };
00037
00038 static const struct rid_name_map everyone_users[] = {
00039 { 0, "Everyone" },
00040 { 0, NULL}};
00041
00042 static const struct rid_name_map creator_owner_users[] = {
00043 { 0, "Creator Owner" },
00044 { 1, "Creator Group" },
00045 { 0, NULL}};
00046
00047 static const struct rid_name_map nt_authority_users[] = {
00048 { 1, "Dialup" },
00049 { 2, "Network"},
00050 { 3, "Batch"},
00051 { 4, "Interactive"},
00052 { 6, "Service"},
00053 { 7, "AnonymousLogon"},
00054 { 8, "Proxy"},
00055 { 9, "ServerLogon"},
00056 { 10, "Self"},
00057 { 11, "Authenticated Users"},
00058 { 12, "Restricted"},
00059 { 13, "Terminal Server User"},
00060 { 14, "Remote Interactive Logon"},
00061 { 15, "This Organization"},
00062 { 18, "SYSTEM"},
00063 { 19, "Local Service"},
00064 { 20, "Network Service"},
00065 { 0, NULL}};
00066
00067 static struct sid_name_map_info special_domains[] = {
00068 { &global_sid_World_Domain, "", everyone_users },
00069 { &global_sid_Creator_Owner_Domain, "", creator_owner_users },
00070 { &global_sid_NT_Authority, "NT Authority", nt_authority_users },
00071 { NULL, NULL, NULL }};
00072
00073 BOOL sid_check_is_wellknown_domain(const DOM_SID *sid, const char **name)
00074 {
00075 int i;
00076
00077 for (i=0; special_domains[i].sid != NULL; i++) {
00078 if (sid_equal(sid, special_domains[i].sid)) {
00079 if (name != NULL) {
00080 *name = special_domains[i].name;
00081 }
00082 return True;
00083 }
00084 }
00085 return False;
00086 }
00087
00088 BOOL sid_check_is_in_wellknown_domain(const DOM_SID *sid)
00089 {
00090 DOM_SID dom_sid;
00091 uint32 rid;
00092
00093 sid_copy(&dom_sid, sid);
00094 sid_split_rid(&dom_sid, &rid);
00095
00096 return sid_check_is_wellknown_domain(&dom_sid, NULL);
00097 }
00098
00099
00100
00101
00102
00103 BOOL lookup_wellknown_sid(TALLOC_CTX *mem_ctx, const DOM_SID *sid,
00104 const char **domain, const char **name)
00105 {
00106 int i;
00107 DOM_SID dom_sid;
00108 uint32 rid;
00109 const struct rid_name_map *users = NULL;
00110
00111 sid_copy(&dom_sid, sid);
00112 if (!sid_split_rid(&dom_sid, &rid)) {
00113 DEBUG(2, ("Could not split rid from SID\n"));
00114 return False;
00115 }
00116
00117 for (i=0; special_domains[i].sid != NULL; i++) {
00118 if (sid_equal(&dom_sid, special_domains[i].sid)) {
00119 *domain = talloc_strdup(mem_ctx,
00120 special_domains[i].name);
00121 users = special_domains[i].known_users;
00122 break;
00123 }
00124 }
00125
00126 if (users == NULL) {
00127 DEBUG(10, ("SID %s is no special sid\n",
00128 sid_string_static(sid)));
00129 return False;
00130 }
00131
00132 for (i=0; users[i].name != NULL; i++) {
00133 if (rid == users[i].rid) {
00134 *name = talloc_strdup(mem_ctx, users[i].name);
00135 return True;
00136 }
00137 }
00138
00139 DEBUG(10, ("RID of special SID %s not found\n",
00140 sid_string_static(sid)));
00141
00142 return False;
00143 }
00144
00145
00146
00147
00148
00149 BOOL lookup_wellknown_name(TALLOC_CTX *mem_ctx, const char *name,
00150 DOM_SID *sid, const char **domain)
00151 {
00152 int i, j;
00153
00154 DEBUG(10,("map_name_to_wellknown_sid: looking up %s\n", name));
00155
00156 for (i=0; special_domains[i].sid != NULL; i++) {
00157 const struct rid_name_map *users =
00158 special_domains[i].known_users;
00159
00160 if (users == NULL)
00161 continue;
00162
00163 for (j=0; users[j].name != NULL; j++) {
00164 if ( strequal(users[j].name, name) ) {
00165 sid_copy(sid, special_domains[i].sid);
00166 sid_append_rid(sid, users[j].rid);
00167 *domain = talloc_strdup(
00168 mem_ctx, special_domains[i].name);
00169 return True;
00170 }
00171 }
00172 }
00173
00174 return False;
00175 }