diff options
Diffstat (limited to 'source3/smbd/session.c')
-rw-r--r-- | source3/smbd/session.c | 74 |
1 files changed, 26 insertions, 48 deletions
diff --git a/source3/smbd/session.c b/source3/smbd/session.c index 54b7a24b07..dade953ec1 100644 --- a/source3/smbd/session.c +++ b/source3/smbd/session.c @@ -27,22 +27,21 @@ #include "includes.h" +extern fstring remote_machine; + static TDB_CONTEXT *tdb; /* called when a session is created */ BOOL session_claim(user_struct *vuser) { - int i = 0; + int i; 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_keystr = NULL; + vuser->session_id = 0; /* don't register sessions for the guest user - its just too expensive to go through pam session code for browsing etc */ @@ -64,37 +63,18 @@ BOOL session_claim(user_struct *vuser) data.dptr = NULL; data.dsize = 0; -#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); - + for (i=1;i<MAX_SESSION_ID;i++) { + slprintf(keystr, sizeof(keystr)-1, "ID/%d", i); key.dptr = keystr; key.dsize = strlen(keystr)+1; - - tdb_store_flag = TDB_REPLACE; + + 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; } /* If 'hostname lookup' == yes, then do the DNS lookup. This is @@ -110,25 +90,24 @@ BOOL session_claim(user_struct *vuser) fstrcpy(sessionid.username, vuser->user.unix_name); fstrcpy(sessionid.hostname, hostname); - sessionid.id_num = i; /* Only valid for utmp sessions */ + slprintf(sessionid.id_str, sizeof(sessionid.id_str)-1, SESSION_TEMPLATE, i); + sessionid.id_num = i; sessionid.pid = pid; sessionid.uid = vuser->uid; sessionid.gid = vuser->gid; - fstrcpy(sessionid.remote_machine, get_remote_machine_name()); + fstrcpy(sessionid.remote_machine, remote_machine); fstrcpy(sessionid.ip_addr, client_addr()); 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)); - if (tdb_store_flag == TDB_MODIFY) { - tdb_delete(tdb, key); - } + tdb_delete(tdb, key); return False; } data.dptr = (char *)&sessionid; data.dsize = sizeof(sessionid); - if (tdb_store(tdb, key, data, tdb_store_flag) != 0) { + if (tdb_store(tdb, key, data, TDB_MODIFY) != 0) { DEBUG(1,("session_claim: unable to create session id record\n")); return False; } @@ -140,11 +119,7 @@ BOOL session_claim(user_struct *vuser) } #endif - vuser->session_keystr = strdup(keystr); - if (!vuser->session_keystr) { - DEBUG(0, ("session_claim: strdup() failed for session_keystr\n")); - return False; - } + vuser->session_id = i; return True; } @@ -154,15 +129,18 @@ void session_yield(user_struct *vuser) TDB_DATA dbuf; struct sessionid sessionid; TDB_DATA key; + fstring keystr; if (!tdb) return; - if (!vuser->session_keystr) { + if (vuser->session_id == 0) { return; } - key.dptr = vuser->session_keystr; - key.dsize = strlen(vuser->session_keystr)+1; + slprintf(keystr, sizeof(keystr)-1, "ID/%d", vuser->session_id); + + key.dptr = keystr; + key.dsize = strlen(keystr)+1; dbuf = tdb_fetch(tdb, key); |