summaryrefslogtreecommitdiff
path: root/source3/smbd
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2010-04-09 17:19:13 +0200
committerVolker Lendecke <vl@samba.org>2010-04-13 09:30:06 +0200
commit5fc2801c09cdfe74253b52b9bf93d7ecad1a98cf (patch)
tree852ede409120b9e42be52bcfb7cc432a679b6bfa /source3/smbd
parentc116d80053fc21519836008e2782c06c7313d512 (diff)
downloadsamba-5fc2801c09cdfe74253b52b9bf93d7ecad1a98cf.tar.gz
samba-5fc2801c09cdfe74253b52b9bf93d7ecad1a98cf.tar.bz2
samba-5fc2801c09cdfe74253b52b9bf93d7ecad1a98cf.zip
s3: Cache the username map in gencache
This is for uses with a heavy-weight username map script
Diffstat (limited to 'source3/smbd')
-rw-r--r--source3/smbd/map_username.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/source3/smbd/map_username.c b/source3/smbd/map_username.c
index 8c8eb2ed9d..dc5d48efaa 100644
--- a/source3/smbd/map_username.c
+++ b/source3/smbd/map_username.c
@@ -76,6 +76,48 @@ static char *skip_space(char *s)
return s;
}
+static bool fetch_map_from_gencache(fstring user)
+{
+ char *key, *value;
+ bool found;
+
+ if (lp_username_map_cache_time() == 0) {
+ return false;
+ }
+
+ key = talloc_asprintf_strupper_m(talloc_tos(), "USERNAME_MAP/%s",
+ user);
+ if (key == NULL) {
+ return false;
+ }
+ found = gencache_get(key, &value, NULL);
+ TALLOC_FREE(key);
+ if (!found) {
+ return false;
+ }
+ fstrcpy(user, value);
+ SAFE_FREE(value);
+ return true;
+}
+
+static void store_map_in_gencache(const char *from, const char *to)
+{
+ char *key;
+ int cache_time = lp_username_map_cache_time();
+
+ if (cache_time == 0) {
+ return;
+ }
+
+ key = talloc_asprintf_strupper_m(talloc_tos(), "USERNAME_MAP/%s",
+ from);
+ if (key == NULL) {
+ return;
+ }
+ gencache_set(key, to, cache_time + time(NULL));
+ TALLOC_FREE(key);
+}
+
bool map_username(struct smbd_server_connection *sconn, fstring user)
{
XFILE *f;
@@ -97,6 +139,10 @@ bool map_username(struct smbd_server_connection *sconn, fstring user)
return true;
}
+ if (fetch_map_from_gencache(user)) {
+ return true;
+ }
+
/* first try the username map script */
if ( *cmd ) {
@@ -134,6 +180,7 @@ bool map_username(struct smbd_server_connection *sconn, fstring user)
if (numlines && qlines) {
DEBUG(3,("Mapped user %s to %s\n", user, qlines[0] ));
set_last_from_to(user, qlines[0]);
+ store_map_in_gencache(user, qlines[0]);
fstrcpy( user, qlines[0] );
}
@@ -197,6 +244,7 @@ bool map_username(struct smbd_server_connection *sconn, fstring user)
mapped_user = True;
set_last_from_to(user, unixname);
+ store_map_in_gencache(user, unixname);
fstrcpy( user, unixname );
if ( return_if_mapped ) {
@@ -217,6 +265,7 @@ bool map_username(struct smbd_server_connection *sconn, fstring user)
*/
set_last_from_to(user, user);
+ store_map_in_gencache(user, user);
return mapped_user;
}