summaryrefslogtreecommitdiff
path: root/source3/smbd
diff options
context:
space:
mode:
Diffstat (limited to 'source3/smbd')
-rw-r--r--source3/smbd/session.c132
1 files changed, 33 insertions, 99 deletions
diff --git a/source3/smbd/session.c b/source3/smbd/session.c
index 6b0263e122..01a8194d2f 100644
--- a/source3/smbd/session.c
+++ b/source3/smbd/session.c
@@ -42,96 +42,40 @@
bool session_claim(struct smbXsrv_session *session)
{
- struct user_struct *vuser = session->compat;
- struct smbd_server_connection *sconn = session->connection->sconn;
- struct server_id pid = messaging_server_id(sconn->msg_ctx);
- TDB_DATA data;
- struct sessionid sessionid;
- fstring keystr;
- struct db_record *rec;
- NTSTATUS status;
- char *raddr;
-
- vuser->session_keystr = NULL;
+ struct auth_session_info *session_info =
+ session->global->auth_session_info;
+ const char *username;
+ const char *hostname;
+ unsigned int id_num;
+ fstring id_str;
/* don't register sessions for the guest user - its just too
expensive to go through pam session code for browsing etc */
- if (security_session_user_level(vuser->session_info, NULL) < SECURITY_USER) {
- return True;
- }
-
- if (!sessionid_init()) {
- return False;
+ if (security_session_user_level(session_info, NULL) < SECURITY_USER) {
+ return true;
}
- ZERO_STRUCT(sessionid);
+ id_num = session->global->session_global_id;
- sessionid.id_num = session->global->session_global_id;
-
- data.dptr = NULL;
- data.dsize = 0;
-
- snprintf(keystr, sizeof(keystr), "ID/%u", sessionid.id_num);
- snprintf(sessionid.id_str, sizeof(sessionid.id_str),
- "smb/%u", sessionid.id_num);
-
- rec = sessionid_fetch_record(NULL, keystr);
- if (rec == NULL) {
- DEBUG(1, ("Could not lock \"%s\"\n", keystr));
- return False;
- }
-
- raddr = tsocket_address_inet_addr_string(session->connection->remote_address,
- talloc_tos());
- if (raddr == NULL) {
- return false;
- }
+ snprintf(id_str, sizeof(id_str), "smb/%u", id_num);
/* Make clear that we require the optional unix_token in the source3 code */
- SMB_ASSERT(vuser->session_info->unix_token);
-
- fstrcpy(sessionid.username, vuser->session_info->unix_info->unix_name);
- fstrcpy(sessionid.hostname, sconn->remote_hostname);
- sessionid.pid = pid;
- sessionid.uid = vuser->session_info->unix_token->uid;
- sessionid.gid = vuser->session_info->unix_token->gid;
- fstrcpy(sessionid.remote_machine, get_remote_machine_name());
- fstrcpy(sessionid.ip_addr_str, raddr);
- sessionid.connect_start = time(NULL);
-
- 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));
-
- TALLOC_FREE(rec);
- return False;
- }
-
- data.dptr = (uint8 *)&sessionid;
- data.dsize = sizeof(sessionid);
+ SMB_ASSERT(session_info->unix_token);
- status = dbwrap_record_store(rec, data, TDB_REPLACE);
+ username = session_info->unix_info->unix_name;
+ hostname = session->global->channels[0].remote_name;
- TALLOC_FREE(rec);
-
- if (!NT_STATUS_IS_OK(status)) {
- DEBUG(1,("session_claim: unable to create session id "
- "record: %s\n", nt_errstr(status)));
- return False;
+ if (!smb_pam_claim_session(username, id_str, hostname)) {
+ DEBUG(1,("pam_session rejected the session for %s [%s]\n",
+ username, id_str));
+ return false;
}
if (lp_utmp()) {
- sys_utmp_claim(sessionid.username, sessionid.hostname,
- sessionid.id_str, sessionid.id_num);
+ sys_utmp_claim(username, hostname, id_str, id_num);
}
- vuser->session_keystr = talloc_strdup(vuser, keystr);
- if (!vuser->session_keystr) {
- DEBUG(0, ("session_claim: talloc_strdup() failed for session_keystr\n"));
- return False;
- }
- return True;
+ return true;
}
/********************************************************************
@@ -140,38 +84,28 @@ bool session_claim(struct smbXsrv_session *session)
void session_yield(struct smbXsrv_session *session)
{
- struct user_struct *vuser = session->compat;
- struct sessionid sessionid;
- struct db_record *rec;
- TDB_DATA value;
+ struct auth_session_info *session_info =
+ session->global->auth_session_info;
+ const char *username;
+ const char *hostname;
+ unsigned int id_num;
+ fstring id_str = "";
- if (!vuser->session_keystr) {
- return;
- }
-
- rec = sessionid_fetch_record(NULL, vuser->session_keystr);
- if (rec == NULL) {
- return;
- }
+ id_num = session->global->session_global_id;
- value = dbwrap_record_get_value(rec);
+ snprintf(id_str, sizeof(id_str), "smb/%u", id_num);
- if (value.dsize != sizeof(sessionid))
- return;
+ /* Make clear that we require the optional unix_token in the source3 code */
+ SMB_ASSERT(session_info->unix_token);
- memcpy(&sessionid, value.dptr, sizeof(sessionid));
+ username = session_info->unix_info->unix_name;
+ hostname = session->global->channels[0].remote_name;
if (lp_utmp()) {
- sys_utmp_yield(sessionid.username, sessionid.hostname,
- sessionid.id_str, sessionid.id_num);
+ sys_utmp_yield(username, hostname, id_str, id_num);
}
- smb_pam_close_session(sessionid.username, sessionid.id_str,
- sessionid.hostname);
-
- dbwrap_record_delete(rec);
-
- TALLOC_FREE(rec);
+ smb_pam_close_session(username, id_str, hostname);
}
/********************************************************************