2 Unix SMB/Netbios implementation.
4 Password and authentication handling
5 Copyright (C) Jeremy Allison 1996-1998
6 Copyright (C) Luke Kenneth Casson Leighton 1996-1998
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 extern int DEBUGLEVEL
;
29 extern fstring global_myworkgroup
;
31 extern pstring global_myname
;
41 * A list of the rids of well known BUILTIN and Domain users
45 static rid_name builtin_alias_rids
[] =
47 { BUILTIN_ALIAS_RID_ADMINS
, "Administrators" , NULL
},
48 { BUILTIN_ALIAS_RID_USERS
, "Users" , NULL
},
49 { BUILTIN_ALIAS_RID_GUESTS
, "Guests" , NULL
},
50 { BUILTIN_ALIAS_RID_POWER_USERS
, "Power Users" , NULL
},
52 { BUILTIN_ALIAS_RID_ACCOUNT_OPS
, "Account Operators" , NULL
},
53 { BUILTIN_ALIAS_RID_SYSTEM_OPS
, "System Operators" , NULL
},
54 { BUILTIN_ALIAS_RID_PRINT_OPS
, "Print Operators" , NULL
},
55 { BUILTIN_ALIAS_RID_BACKUP_OPS
, "Backup Operators" , NULL
},
56 { BUILTIN_ALIAS_RID_REPLICATOR
, "Replicator" , NULL
},
60 /* array lookup of well-known Domain RID users. */
61 static rid_name domain_user_rids
[] =
63 { DOMAIN_USER_RID_ADMIN
, "Administrator" , NULL
},
64 { DOMAIN_USER_RID_GUEST
, "Guest" , NULL
},
68 /* array lookup of well-known Domain RID groups. */
69 static rid_name domain_group_rids
[] =
71 { DOMAIN_GROUP_RID_ADMINS
, "Domain Admins" , NULL
},
72 { DOMAIN_GROUP_RID_USERS
, "Domain Users" , NULL
},
73 { DOMAIN_GROUP_RID_GUESTS
, "Domain Guests" , NULL
},
77 /*******************************************************************
78 make an entry in wk name map
79 the name is strdup()ed!
80 *******************************************************************/
81 static BOOL
make_alias_entry(rid_name
*map
, char *defaultname
, char *name
)
83 if(isdigit(*defaultname
))
88 if(*defaultname
== '0')
90 if(defaultname
[1] == 'x')
105 sscanf(defaultname
, s
, &rid
);
107 for( ; map
->rid
; map
++)
109 if(map
->rid
== rid
) {
110 map
->name
= strdup(name
);
111 DEBUG(5, ("make_alias_entry: mapping %s (rid 0x%x) to %s\n",
112 map
->defaultname
, map
->rid
, map
->name
));
119 for( ; map
->rid
; map
++)
121 if(!StrCaseCmp(map
->name
, defaultname
)) {
122 map
->name
= strdup(name
);
123 DEBUG(5, ("make_alias_entry: mapping %s (rid 0x%x) to %s\n",
124 map
->defaultname
, map
->rid
, map
->name
));
131 /*******************************************************************
132 reset wk map to default values
133 *******************************************************************/
134 static void reset_wk_map(rid_name
*map
)
136 for( ; map
->rid
; map
++)
138 if(map
->name
!= NULL
&& map
->name
!= map
->defaultname
)
140 map
->name
= map
->defaultname
;
144 /*******************************************************************
146 *******************************************************************/
147 static void reset_wk_maps(void)
149 DEBUG(4, ("reset_wk_maps: Initializing maps\n"));
150 reset_wk_map(builtin_alias_rids
);
151 reset_wk_map(domain_user_rids
);
152 reset_wk_map(domain_group_rids
);
155 /*******************************************************************
156 Load builtin alias map
157 *******************************************************************/
158 static BOOL
load_wk_rid_map(void)
160 static int map_initialized
= 0;
161 static time_t builtin_rid_file_last_modified
= (time_t)0;
162 char *builtin_rid_file
= lp_builtinrid_file();
168 if (!map_initialized
)
174 if (!*builtin_rid_file
)
179 fp
= open_file_if_modified(builtin_rid_file
, "r", &builtin_rid_file_last_modified
);
182 DEBUG(0,("load_wk_rid_map: can't open name map %s. Error was %s\n",
183 builtin_rid_file
, strerror(errno
)));
188 DEBUG(4,("load_wk_rid_map: Scanning builtin rid map %s\n",builtin_rid_file
));
190 while ((s
= fgets_slash(buf
, sizeof(buf
), fp
)) != NULL
)
195 DEBUG(10,("Read line |%s|\n", s
));
197 if (!*s
|| strchr("#;",*s
))
200 if (!next_token(&s
,name
, "\t\n\r=", sizeof(defaultname
)))
203 if (!next_token(&s
,defaultname
, "\t\n\r=", sizeof(name
)))
206 trim_string(defaultname
, " ", " ");
207 trim_string(name
, " ", " ");
209 if (!*defaultname
|| !*name
)
212 if(make_alias_entry(builtin_alias_rids
, defaultname
, name
))
214 if(make_alias_entry(domain_user_rids
, defaultname
, name
))
216 if(make_alias_entry(domain_group_rids
, defaultname
, name
))
219 DEBUG(0,("load_wk_rid_map: Unknown alias %s in map %s\n",
220 defaultname
, builtin_rid_file
));
227 /*******************************************************************
229 ********************************************************************/
230 uint32
lookup_wk_group_name(const char *group_name
, const char *domain
,
231 DOM_SID
*sid
, uint32
*type
)
234 int i
= -1; /* start do loop at -1 */
237 if (strequal(domain
, global_sam_name
))
239 sid_copy(sid
, &global_sam_sid
);
241 else if (strequal(domain
, "BUILTIN"))
243 sid_copy(sid
, global_sid_builtin
);
247 return 0xC0000000 | NT_STATUS_NONE_MAPPED
;
252 do /* find, if it exists, a group rid for the group name */
255 rid
= domain_group_rids
[i
].rid
;
256 grp_name
= domain_group_rids
[i
].name
;
258 if (strequal(grp_name
, group_name
))
260 sid_append_rid(sid
, rid
);
261 (*type
) = SID_NAME_DOM_GRP
;
266 } while (grp_name
!= NULL
);
268 return 0xC0000000 | NT_STATUS_NONE_MAPPED
;
271 /*******************************************************************
273 ********************************************************************/
274 uint32
lookup_wk_user_name(const char *user_name
, const char *domain
,
275 DOM_SID
*sid
, uint32
*type
)
278 int i
= -1; /* start do loop at -1 */
280 if (strequal(domain
, global_sam_name
))
282 sid_copy(sid
, &global_sam_sid
);
284 else if (strequal(domain
, "BUILTIN"))
286 sid_copy(sid
, global_sid_builtin
);
290 return 0xC0000000 | NT_STATUS_NONE_MAPPED
;
295 do /* find, if it exists, a alias rid for the alias name */
298 usr_name
= domain_user_rids
[i
].name
;
300 } while (usr_name
!= NULL
&& !strequal(usr_name
, user_name
));
302 if (usr_name
!= NULL
)
304 sid_append_rid(sid
, domain_user_rids
[i
].rid
);
305 (*type
) = SID_NAME_USER
;
309 return 0xC0000000 | NT_STATUS_NONE_MAPPED
;
312 /*******************************************************************
313 lookup_builtin_alias_name
314 ********************************************************************/
315 uint32
lookup_builtin_alias_name(const char *alias_name
, const char *domain
,
316 DOM_SID
*sid
, uint32
*type
)
322 if (strequal(domain
, "BUILTIN"))
326 sid_copy(sid
, global_sid_builtin
);
331 return 0xC0000000 | NT_STATUS_NONE_MAPPED
;
336 do /* find, if it exists, a alias rid for the alias name*/
338 rid
= builtin_alias_rids
[i
].rid
;
339 als_name
= builtin_alias_rids
[i
].name
;
341 if (strequal(als_name
, alias_name
))
345 sid_append_rid(sid
, rid
);
350 (*type
) = SID_NAME_ALIAS
;
358 } while (als_name
!= NULL
);
360 return 0xC0000000 | NT_STATUS_NONE_MAPPED
;
363 /*************************************************************
364 the following functions lookup wk rid's.
365 these may be unnecessary...
366 **************************************************************/
367 static char *lookup_wk_rid(uint32 rid
, rid_name
*table
)
370 for( ; table
->rid
; table
++)
372 if(table
->rid
== rid
)
380 char *lookup_wk_alias_rid(uint32 rid
)
382 return lookup_wk_rid(rid
, builtin_alias_rids
);
385 char *lookup_wk_user_rid(uint32 rid
)
387 return lookup_wk_rid(rid
, domain_user_rids
);
390 char *lookup_wk_group_rid(uint32 rid
)
392 return lookup_wk_rid(rid
, domain_group_rids
);