#include "includes.h"
static TDB_CONTEXT *tdb;
+
+BOOL session_init(void)
+{
+ if (tdb)
+ return True;
+
+ tdb = tdb_open_log(lock_path("sessionid.tdb"), 0, TDB_CLEAR_IF_FIRST|TDB_DEFAULT,
+ O_RDWR | O_CREAT, 0644);
+ if (!tdb) {
+ DEBUG(1,("session_init: failed to open sessionid tdb\n"));
+ return False;
+ }
+
+ return True;
+}
+
/* called when a session is created */
BOOL session_claim(user_struct *vuser)
{
int i = 0;
TDB_DATA data;
+ struct sockaddr sa;
+ struct in_addr *client_ip;
struct sessionid sessionid;
uint32 pid = (uint32)sys_getpid();
TDB_DATA key;
return True;
}
- if (!tdb) {
- tdb = tdb_open_log(lock_path("sessionid.tdb"), 0, TDB_CLEAR_IF_FIRST|TDB_DEFAULT,
- O_RDWR | O_CREAT, 0644);
- if (!tdb) {
- DEBUG(1,("session_claim: failed to open sessionid tdb\n"));
- return False;
- }
- }
+ if (!session_init())
+ return False;
ZERO_STRUCT(sessionid);
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);
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(),
}
/* If 'hostname lookup' == yes, then do the DNS lookup. This is
- needed becouse utmp and PAM both expect DNS names
+ needed because utmp and PAM both expect DNS names
client_name() handles this case internally.
*/
fstrcpy(sessionid.remote_machine, get_remote_machine_name());
fstrcpy(sessionid.ip_addr, client_addr());
+ client_ip = client_inaddr(&sa);
+
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));
return False;
}
-#if WITH_UTMP
if (lp_utmp()) {
sys_utmp_claim(sessionid.username, sessionid.hostname,
+ client_ip,
sessionid.id_str, sessionid.id_num);
}
-#endif
- vuser->session_keystr = strdup(keystr);
+ vuser->session_keystr = SMB_STRDUP(keystr);
if (!vuser->session_keystr) {
DEBUG(0, ("session_claim: strdup() failed for session_keystr\n"));
return False;
{
TDB_DATA dbuf;
struct sessionid sessionid;
- TDB_DATA key;
+ struct in_addr *client_ip;
+ TDB_DATA key;
if (!tdb) return;
memcpy(&sessionid, dbuf.dptr, sizeof(sessionid));
+ client_ip = interpret_addr2(sessionid.ip_addr);
+
SAFE_FREE(dbuf.dptr);
-#if WITH_UTMP
if (lp_utmp()) {
sys_utmp_yield(sessionid.username, sessionid.hostname,
+ client_ip,
sessionid.id_str, sessionid.id_num);
}
-#endif
smb_pam_close_session(sessionid.username, sessionid.id_str, sessionid.hostname);
static BOOL session_traverse(int (*fn)(TDB_CONTEXT *, TDB_DATA, TDB_DATA, void *), void *state)
{
- if (!tdb) {
+ if (!session_init()) {
DEBUG(3, ("No tdb opened\n"));
return False;
}
const struct sessionid *current = (const struct sessionid *) dbuf.dptr;
sesslist->count += 1;
- sesslist->sessions = REALLOC(sesslist->sessions, sesslist->count *
- sizeof(struct sessionid));
+ sesslist->sessions = SMB_REALLOC_ARRAY(sesslist->sessions, struct sessionid,
+ sesslist->count);
memcpy(&sesslist->sessions[sesslist->count - 1], current,
sizeof(struct sessionid));
*session_list = sesslist.sessions;
return sesslist.count;
}
-