summaryrefslogtreecommitdiff
path: root/source3/smbd
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2007-12-17 17:27:29 -0800
committerJeremy Allison <jra@samba.org>2007-12-17 17:27:29 -0800
commit192aae0564c641fa06f90a064c033fa52d8cf549 (patch)
treed47de6f292dcfaba688468cd0108ef788f8ff806 /source3/smbd
parent5bfe3c49a1b5ee0fad40e83326cf8b4bc88240f5 (diff)
downloadsamba-192aae0564c641fa06f90a064c033fa52d8cf549.tar.gz
samba-192aae0564c641fa06f90a064c033fa52d8cf549.tar.bz2
samba-192aae0564c641fa06f90a064c033fa52d8cf549.zip
Remove more static fstrings (yes this little cache should be
in the rbtree....). Jeremy. (This used to be commit 97cfdae4052d46a35040d4c1a4ade8bf2c41dbc7)
Diffstat (limited to 'source3/smbd')
-rw-r--r--source3/smbd/map_username.c68
1 files changed, 49 insertions, 19 deletions
diff --git a/source3/smbd/map_username.c b/source3/smbd/map_username.c
index c04e0f1ae2..bde755eff6 100644
--- a/source3/smbd/map_username.c
+++ b/source3/smbd/map_username.c
@@ -32,10 +32,45 @@
Returns True if username was changed, false otherwise.
********************************************************************/
+static char *last_from, *last_to;
+
+static const char *get_last_from(void)
+{
+ if (!last_from) {
+ return "";
+ }
+ return last_from;
+}
+
+static const char *get_last_to(void)
+{
+ if (!last_to) {
+ return "";
+ }
+ return last_to;
+}
+
+static bool set_last_from_to(const char *from, const char *to)
+{
+ char *orig_from = last_from;
+ char *orig_to = last_to;
+
+ last_from = SMB_STRDUP(from);
+ last_to = SMB_STRDUP(to);
+
+ SAFE_FREE(orig_from);
+ SAFE_FREE(orig_to);
+
+ if (!last_from || !last_to) {
+ SAFE_FREE(last_from);
+ SAFE_FREE(last_to);
+ return false;
+ }
+ return true;
+}
+
bool map_username(fstring user)
{
- static bool initialised=False;
- static fstring last_from,last_to;
XFILE *f;
char *mapfile = lp_username_map();
char *s;
@@ -46,12 +81,12 @@ bool map_username(fstring user)
if (!*user)
return false;
- if (strequal(user,last_to))
+ if (strequal(user,get_last_to()))
return false;
- if (strequal(user,last_from)) {
- DEBUG(3,("Mapped user %s to %s\n",user,last_to));
- fstrcpy(user,last_to);
+ if (strequal(user,get_last_from())) {
+ DEBUG(3,("Mapped user %s to %s\n",user,get_last_to()));
+ fstrcpy(user,get_last_to());
return true;
}
@@ -98,15 +133,9 @@ bool map_username(fstring user)
}
/* ok. let's try the mapfile */
-
if (!*mapfile)
return False;
- if (!initialised) {
- *last_from = *last_to = 0;
- initialised = True;
- }
-
f = x_fopen(mapfile,O_RDONLY, 0);
if (!f) {
DEBUG(0,("can't open username map %s. Error %s\n",mapfile, strerror(errno) ));
@@ -135,7 +164,7 @@ bool map_username(fstring user)
while (*unixname && isspace((int)*unixname))
unixname++;
}
-
+
if (!*unixname || strchr_m("#;",*unixname))
continue;
@@ -159,27 +188,28 @@ bool map_username(fstring user)
user_in_list(user, (const char **)dosuserlist)) {
DEBUG(3,("Mapped user %s to %s\n",user,unixname));
mapped_user = True;
- fstrcpy( last_from,user );
+
+ set_last_from_to(user, unixname);
fstrcpy( user, unixname );
- fstrcpy( last_to,user );
+
if ( return_if_mapped ) {
str_list_free (&dosuserlist);
x_fclose(f);
return True;
}
}
-
+
str_list_free (&dosuserlist);
}
x_fclose(f);
/*
- * Setup the last_from and last_to as an optimization so
+ * Setup the last_from and last_to as an optimization so
* that we don't scan the file again for the same user.
*/
- fstrcpy(last_from,user);
- fstrcpy(last_to,user);
+
+ set_last_from_to(user, user);
return mapped_user;
}