[SCM] Samba Shared Repository - branch v3-2-test updated -
initial-v3-2-unstable-708-g97cfdae
Jeremy Allison
jra at samba.org
Tue Dec 18 01:28:05 GMT 2007
The branch, v3-2-test has been updated
via 97cfdae4052d46a35040d4c1a4ade8bf2c41dbc7 (commit)
from 299ea5d122e173adf6edb6399fc90798747b0c97 (commit)
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-2-test
- Log -----------------------------------------------------------------
commit 97cfdae4052d46a35040d4c1a4ade8bf2c41dbc7
Author: Jeremy Allison <jra at samba.org>
Date: Mon Dec 17 17:27:29 2007 -0800
Remove more static fstrings (yes this little cache should be
in the rbtree....).
Jeremy.
-----------------------------------------------------------------------
Summary of changes:
source/smbd/map_username.c | 68 +++++++++++++++++++++++++++++++------------
1 files changed, 49 insertions(+), 19 deletions(-)
Changeset truncated at 500 lines:
diff --git a/source/smbd/map_username.c b/source/smbd/map_username.c
index c04e0f1..bde755e 100644
--- a/source/smbd/map_username.c
+++ b/source/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;
}
--
Samba Shared Repository
More information about the samba-cvs
mailing list