summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/domain_namemap.c22
-rw-r--r--source3/lib/util_file.c53
-rw-r--r--source3/lib/util_pwdb.c235
3 files changed, 262 insertions, 48 deletions
diff --git a/source3/lib/domain_namemap.c b/source3/lib/domain_namemap.c
index 156e4e7d35..fb6ecf2acf 100644
--- a/source3/lib/domain_namemap.c
+++ b/source3/lib/domain_namemap.c
@@ -479,7 +479,6 @@ static ubi_slList *load_name_map(DOM_MAP_TYPE type)
char *aliasname_map_file = lp_aliasname_map();
char *ntusrname_map_file = lp_ntusrname_map();
- SMB_STRUCT_STAT st;
FILE *fp;
char *s;
pstring buf;
@@ -533,32 +532,13 @@ static ubi_slList *load_name_map(DOM_MAP_TYPE type)
return map_list;
}
- if (sys_stat(map_file, &st) != 0)
- {
- DEBUG(0, ("load_name_map: Unable to stat file %s. Error was %s\n",
- map_file, strerror(errno) ));
- return map_list;
- }
-
- /*
- * Check if file has changed.
- */
- if (st.st_mtime <= (*file_last_modified))
- {
- return map_list;
- }
-
- (*file_last_modified) = st.st_mtime;
-
/*
* Load the file.
*/
- fp = fopen(map_file,"r");
+ fp = open_file_if_modified(map_file, "r", file_last_modified);
if (!fp)
{
- DEBUG(0,("load_name_map: can't open name map %s. Error was %s\n",
- map_file, strerror(errno)));
return map_list;
}
diff --git a/source3/lib/util_file.c b/source3/lib/util_file.c
index 37489086d8..5861314c02 100644
--- a/source3/lib/util_file.c
+++ b/source3/lib/util_file.c
@@ -188,7 +188,6 @@ int getfileline(void *vp, char *linebuf, int linebuf_size)
/* Static buffers we will return. */
FILE *fp = (FILE *)vp;
unsigned char c;
- unsigned char *p;
size_t linebuf_len;
if (fp == NULL)
@@ -248,12 +247,6 @@ int getfileline(void *vp, char *linebuf, int linebuf_size)
continue;
}
- p = (unsigned char *) strchr(linebuf, ':');
- if (p == NULL)
- {
- DEBUG(0, ("getfileline: malformed line entry (no :)\n"));
- continue;
- }
return linebuf_len;
}
return -1;
@@ -326,3 +319,49 @@ char *fgets_slash(char *s2,int maxlen,FILE *f)
return(s);
}
+/****************************************************************************
+checks if a file has changed since last read
+****************************************************************************/
+BOOL file_modified(const char *filename, time_t *lastmodified)
+{
+ SMB_STRUCT_STAT st;
+
+ if (sys_stat(filename, &st) != 0)
+ {
+ DEBUG(0, ("file_changed: Unable to stat file %s. Error was %s\n",
+ filename, strerror(errno) ));
+ return False;
+ }
+
+ if(st.st_mtime <= *lastmodified)
+ {
+ DEBUG(20, ("file_modified: %s not modified\n", filename));
+ return False;
+ }
+
+ DEBUG(20, ("file_modified: %s modified\n", filename));
+ *lastmodified = st.st_mtime;
+ return True;
+}
+
+/***************************************************************************
+opens a file if modified otherwise returns NULL
+***************************************************************************/
+void *open_file_if_modified(const char *filename, char *mode, time_t *lastmodified)
+{
+ FILE *f;
+
+ if (file_modified(filename, lastmodified))
+ {
+ return NULL;
+ }
+
+ if( (f = fopen(filename, mode)) == NULL)
+ {
+ DEBUG(0, ("open_file_if_modified: can't open file %s. Error was %s\n",
+ filename, strerror(errno)));
+ return NULL;
+ }
+
+ return (void *)f;
+}
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);
+}
+