summaryrefslogtreecommitdiff
path: root/source3/smbd
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2002-07-28 02:23:22 +0000
committerAndrew Bartlett <abartlet@samba.org>2002-07-28 02:23:22 +0000
commite39b6dbff3464f621d40d53e03f5f5e3abf5162a (patch)
treeef8cf7d4195f3aa5c4da640258cf1a5b3f9d7848 /source3/smbd
parent74d235ff1a08f931a85f7715526344d0e08ccfd4 (diff)
downloadsamba-e39b6dbff3464f621d40d53e03f5f5e3abf5162a.tar.gz
samba-e39b6dbff3464f621d40d53e03f5f5e3abf5162a.tar.bz2
samba-e39b6dbff3464f621d40d53e03f5f5e3abf5162a.zip
Another item off my long-term todo list:
Remove the n^2 search for valid 'tty' names from the sesion code when we don't actually need it. Its main value is in getting 'well behaved' numbers for use with utmp, so when we are not doing utmp we don't need this to get in the way. Andrew Bartlett (This used to be commit 50507e131dac19485a2561f3448da7334e357f50)
Diffstat (limited to 'source3/smbd')
-rw-r--r--source3/smbd/session.c70
1 files changed, 47 insertions, 23 deletions
diff --git a/source3/smbd/session.c b/source3/smbd/session.c
index dade953ec1..f7ade5570c 100644
--- a/source3/smbd/session.c
+++ b/source3/smbd/session.c
@@ -33,15 +33,18 @@ static TDB_CONTEXT *tdb;
/* called when a session is created */
BOOL session_claim(user_struct *vuser)
{
- int i;
+ int i = 0;
TDB_DATA data;
struct sessionid sessionid;
uint32 pid = (uint32)sys_getpid();
TDB_DATA key;
fstring keystr;
char * hostname;
+ int tdb_store_flag; /* If using utmp, we do an inital 'lock hold' store,
+ but we don't need this if we are just using the
+ (unique) pid/vuid combination */
- vuser->session_id = 0;
+ vuser->session_keystr = NULL;
/* don't register sessions for the guest user - its just too
expensive to go through pam session code for browsing etc */
@@ -63,18 +66,37 @@ BOOL session_claim(user_struct *vuser)
data.dptr = NULL;
data.dsize = 0;
- for (i=1;i<MAX_SESSION_ID;i++) {
- slprintf(keystr, sizeof(keystr)-1, "ID/%d", i);
+#if WITH_UTMP
+ if (lp_utmp()) {
+ for (i=1;i<MAX_SESSION_ID;i++) {
+ slprintf(keystr, sizeof(keystr)-1, "ID/%d", i);
+ key.dptr = keystr;
+ key.dsize = strlen(keystr)+1;
+
+ if (tdb_store(tdb, key, data, TDB_INSERT) == 0) break;
+ }
+
+ if (i == MAX_SESSION_ID) {
+ DEBUG(1,("session_claim: out of session IDs (max is %d)\n",
+ MAX_SESSION_ID));
+ return False;
+ }
+ slprintf(sessionid.id_str, sizeof(sessionid.id_str)-1, SESSION_UTMP_TEMPLATE, i);
+ tdb_store_flag = TDB_MODIFY;
+ } else
+#endif
+ {
+ slprintf(keystr, sizeof(keystr)-1, "ID/%lu/%u",
+ (long unsigned int)sys_getpid(),
+ vuser->vuid);
+ slprintf(sessionid.id_str, sizeof(sessionid.id_str)-1,
+ SESSION_TEMPLATE, (long unsigned int)sys_getpid(),
+ vuser->vuid);
+
key.dptr = keystr;
key.dsize = strlen(keystr)+1;
-
- if (tdb_store(tdb, key, data, TDB_INSERT) == 0) break;
- }
-
- if (i == MAX_SESSION_ID) {
- DEBUG(1,("session_claim: out of session IDs (max is %d)\n",
- MAX_SESSION_ID));
- return False;
+
+ tdb_store_flag = TDB_REPLACE;
}
/* If 'hostname lookup' == yes, then do the DNS lookup. This is
@@ -90,8 +112,7 @@ BOOL session_claim(user_struct *vuser)
fstrcpy(sessionid.username, vuser->user.unix_name);
fstrcpy(sessionid.hostname, hostname);
- slprintf(sessionid.id_str, sizeof(sessionid.id_str)-1, SESSION_TEMPLATE, i);
- sessionid.id_num = i;
+ sessionid.id_num = i; /* Only valid for utmp sessions */
sessionid.pid = pid;
sessionid.uid = vuser->uid;
sessionid.gid = vuser->gid;
@@ -101,13 +122,15 @@ BOOL session_claim(user_struct *vuser)
if (!smb_pam_claim_session(sessionid.username, sessionid.id_str, sessionid.hostname)) {
DEBUG(1,("pam_session rejected the session for %s [%s]\n",
sessionid.username, sessionid.id_str));
- tdb_delete(tdb, key);
+ if (tdb_store_flag == TDB_MODIFY) {
+ tdb_delete(tdb, key);
+ }
return False;
}
data.dptr = (char *)&sessionid;
data.dsize = sizeof(sessionid);
- if (tdb_store(tdb, key, data, TDB_MODIFY) != 0) {
+ if (tdb_store(tdb, key, data, tdb_store_flag) != 0) {
DEBUG(1,("session_claim: unable to create session id record\n"));
return False;
}
@@ -119,7 +142,11 @@ BOOL session_claim(user_struct *vuser)
}
#endif
- vuser->session_id = i;
+ vuser->session_keystr = strdup(keystr);
+ if (!vuser->session_keystr) {
+ DEBUG(0, ("session_claim: strdup() failed for session_keystr\n"));
+ return False;
+ }
return True;
}
@@ -129,18 +156,15 @@ void session_yield(user_struct *vuser)
TDB_DATA dbuf;
struct sessionid sessionid;
TDB_DATA key;
- fstring keystr;
if (!tdb) return;
- if (vuser->session_id == 0) {
+ if (!vuser->session_keystr) {
return;
}
- slprintf(keystr, sizeof(keystr)-1, "ID/%d", vuser->session_id);
-
- key.dptr = keystr;
- key.dsize = strlen(keystr)+1;
+ key.dptr = vuser->session_keystr;
+ key.dsize = strlen(vuser->session_keystr)+1;
dbuf = tdb_fetch(tdb, key);