diff options
author | Luke Leighton <lkcl@samba.org> | 1999-07-14 19:21:44 +0000 |
---|---|---|
committer | Luke Leighton <lkcl@samba.org> | 1999-07-14 19:21:44 +0000 |
commit | 1f33d5a8aaa6b9a94dde21529fe2aa407fb5ffa1 (patch) | |
tree | 9dabf92f0bc5923d3d4f48c7a2eb4fcd1322f4a5 /source3/lib/util_pwdb.c | |
parent | c553c01c86bca04583277f65d45d0e097fa38603 (diff) | |
download | samba-1f33d5a8aaa6b9a94dde21529fe2aa407fb5ffa1.tar.gz samba-1f33d5a8aaa6b9a94dde21529fe2aa407fb5ffa1.tar.bz2 samba-1f33d5a8aaa6b9a94dde21529fe2aa407fb5ffa1.zip |
code from bertl to allow remap of default built-in names to anything.
parameter is "builtin rid file".
Copyright 1999 Bertl <bp@vpnet.at>
(This used to be commit 80d36778432d42eb265ed9428f27a27250ba5e08)
Diffstat (limited to 'source3/lib/util_pwdb.c')
-rw-r--r-- | source3/lib/util_pwdb.c | 235 |
1 files changed, 215 insertions, 20 deletions
diff --git a/source3/lib/util_pwdb.c b/source3/lib/util_pwdb.c index b3b638b5e6..f78bdfff5d 100644 --- a/source3/lib/util_pwdb.c +++ b/source3/lib/util_pwdb.c @@ -34,43 +34,199 @@ extern DOM_SID global_sid_S_1_5_20; extern pstring global_myname; +typedef struct +{ + uint32 rid; + char *defaultname; + char *name; +} rid_name; + /* * A list of the rids of well known BUILTIN and Domain users * and groups. */ -rid_name builtin_alias_rids[] = +static rid_name builtin_alias_rids[] = { - { BUILTIN_ALIAS_RID_ADMINS , "Administrators" }, - { BUILTIN_ALIAS_RID_USERS , "Users" }, - { BUILTIN_ALIAS_RID_GUESTS , "Guests" }, - { BUILTIN_ALIAS_RID_POWER_USERS , "Power Users" }, + { BUILTIN_ALIAS_RID_ADMINS , "Administrators" , NULL }, + { BUILTIN_ALIAS_RID_USERS , "Users" , NULL }, + { BUILTIN_ALIAS_RID_GUESTS , "Guests" , NULL }, + { BUILTIN_ALIAS_RID_POWER_USERS , "Power Users" , NULL }, - { BUILTIN_ALIAS_RID_ACCOUNT_OPS , "Account Operators" }, - { BUILTIN_ALIAS_RID_SYSTEM_OPS , "System Operators" }, - { BUILTIN_ALIAS_RID_PRINT_OPS , "Print Operators" }, - { BUILTIN_ALIAS_RID_BACKUP_OPS , "Backup Operators" }, - { BUILTIN_ALIAS_RID_REPLICATOR , "Replicator" }, - { 0 , NULL } + { BUILTIN_ALIAS_RID_ACCOUNT_OPS , "Account Operators" , NULL }, + { BUILTIN_ALIAS_RID_SYSTEM_OPS , "System Operators" , NULL }, + { BUILTIN_ALIAS_RID_PRINT_OPS , "Print Operators" , NULL }, + { BUILTIN_ALIAS_RID_BACKUP_OPS , "Backup Operators" , NULL }, + { BUILTIN_ALIAS_RID_REPLICATOR , "Replicator" , NULL }, + { 0 , NULL , NULL} }; /* array lookup of well-known Domain RID users. */ -rid_name domain_user_rids[] = +static rid_name domain_user_rids[] = { - { DOMAIN_USER_RID_ADMIN , "Administrator" }, - { DOMAIN_USER_RID_GUEST , "Guest" }, - { 0 , NULL } + { DOMAIN_USER_RID_ADMIN , "Administrator" , NULL }, + { DOMAIN_USER_RID_GUEST , "Guest" , NULL }, + { 0 , NULL , NULL} }; /* array lookup of well-known Domain RID groups. */ -rid_name domain_group_rids[] = +static rid_name domain_group_rids[] = { - { DOMAIN_GROUP_RID_ADMINS , "Domain Admins" }, - { DOMAIN_GROUP_RID_USERS , "Domain Users" }, - { DOMAIN_GROUP_RID_GUESTS , "Domain Guests" }, - { 0 , NULL } + { DOMAIN_GROUP_RID_ADMINS , "Domain Admins" , NULL }, + { DOMAIN_GROUP_RID_USERS , "Domain Users" , NULL }, + { DOMAIN_GROUP_RID_GUESTS , "Domain Guests" , NULL }, + { 0 , NULL , NULL} }; +/******************************************************************* + make an entry in wk name map + the name is strdup()ed! + *******************************************************************/ +static BOOL make_alias_entry(rid_name *map, char *defaultname, char *name) +{ + if(isdigit(*defaultname)) + { + long rid = -1; + char *s; + + if(*defaultname == '0') + { + if(defaultname[1] == 'x') + { + s = "%lx"; + defaultname += 2; + } + else + { + s = "%lo"; + } + } + else + { + s = "%ld"; + } + + sscanf(defaultname, s, &rid); + + for( ; map->rid; map++) + { + if(map->rid == rid) { + map->name = strdup(name); + DEBUG(5, ("make_alias_entry: mapping %s (rid 0x%x) to %s\n", + map->defaultname, map->rid, map->name)); + return True; + } + } + return False; + } + + for( ; map->rid; map++) + { + if(!StrCaseCmp(map->name, defaultname)) { + map->name = strdup(name); + DEBUG(5, ("make_alias_entry: mapping %s (rid 0x%x) to %s\n", + map->defaultname, map->rid, map->name)); + return True; + } + } + return False; +} + +/******************************************************************* + reset wk map to default values + *******************************************************************/ +static void reset_wk_map(rid_name *map) +{ + for( ; map->rid; map++) + { + if(map->name != NULL && map->name != map->defaultname) + free(map->name); + map->name = map->defaultname; + } +} + +/******************************************************************* + reset all wk maps + *******************************************************************/ +static void reset_wk_maps(void) +{ + DEBUG(4, ("reset_wk_maps: Initializing maps\n")); + reset_wk_map(builtin_alias_rids); + reset_wk_map(domain_user_rids); + reset_wk_map(domain_group_rids); +} + +/******************************************************************* + Load builtin alias map + *******************************************************************/ +static BOOL load_wk_rid_map(void) +{ + static int map_initialized = 0; + static time_t builtin_rid_file_last_modified = (time_t)0; + char *builtin_rid_file = lp_builtinrid_file(); + + FILE *fp; + char *s; + pstring buf; + + if (!map_initialized) + { + reset_wk_maps(); + map_initialized = 1; + } + + if (!*builtin_rid_file) + { + return False; + } + + fp = open_file_if_modified(builtin_rid_file, "r", &builtin_rid_file_last_modified); + if(!fp) + { + DEBUG(0,("load_wk_rid_map: can't open name map %s. Error was %s\n", + builtin_rid_file, strerror(errno))); + return False; + } + + reset_wk_maps(); + DEBUG(4,("load_wk_rid_map: Scanning builtin rid map %s\n",builtin_rid_file)); + + while ((s = fgets_slash(buf, sizeof(buf), fp)) != NULL) + { + pstring defaultname; + pstring name; + + DEBUG(10,("Read line |%s|\n", s)); + + if (!*s || strchr("#;",*s)) + continue; + + if (!next_token(&s,name, "\t\n\r=", sizeof(defaultname))) + continue; + + if (!next_token(&s,defaultname, "\t\n\r=", sizeof(name))) + continue; + + trim_string(defaultname, " ", " "); + trim_string(name, " ", " "); + + if (!*defaultname || !*name) + continue; + + if(make_alias_entry(builtin_alias_rids, defaultname, name)) + continue; + if(make_alias_entry(domain_user_rids, defaultname, name)) + continue; + if(make_alias_entry(domain_group_rids, defaultname, name)) + continue; + + DEBUG(0,("load_wk_rid_map: Unknown alias %s in map %s\n", + defaultname, builtin_rid_file)); + } + + fclose(fp); + return True; +} /******************************************************************* lookup_wk_group_name @@ -96,6 +252,8 @@ uint32 lookup_wk_group_name(const char *group_name, const char *domain, return 0xC0000000 | NT_STATUS_NONE_MAPPED; } + load_wk_rid_map(); + do /* find, if it exists, a group rid for the group name */ { i++; @@ -137,6 +295,8 @@ uint32 lookup_wk_user_name(const char *user_name, const char *domain, return 0xC0000000 | NT_STATUS_NONE_MAPPED; } + load_wk_rid_map(); + do /* find, if it exists, a alias rid for the alias name */ { i++; @@ -175,6 +335,8 @@ uint32 lookup_builtin_alias_name(const char *alias_name, const char *domain, return 0xC0000000 | NT_STATUS_NONE_MAPPED; } + load_wk_rid_map(); + do /* find, if it exists, a alias rid for the alias name*/ { rid = builtin_alias_rids[i].rid; @@ -471,3 +633,36 @@ BOOL pwdb_initialise(BOOL is_server) return initialise_password_db(); } + +/************************************************************* + the following functions lookup wk rid's. + these may be unnecessary... +**************************************************************/ +static char *lookup_wk_rid(uint32 rid, rid_name *table) +{ + load_wk_rid_map(); + for( ; table->rid ; table++) + { + if(table->rid == rid) + { + return table->name; + } + } + return NULL; +} + +char *lookup_wk_alias_rid(uint32 rid) +{ + return lookup_wk_rid(rid, builtin_alias_rids); +} + +char *lookup_wk_user_rid(uint32 rid) +{ + return lookup_wk_rid(rid, domain_user_rids); +} + +char *lookup_wk_group_rid(uint32 rid) +{ + return lookup_wk_rid(rid, domain_group_rids); +} + |