libcli/smb: add smb1cli_session_set_session_key()
authorStefan Metzmacher <metze@samba.org>
Wed, 1 Aug 2012 06:53:30 +0000 (08:53 +0200)
committerStefan Metzmacher <metze@samba.org>
Wed, 1 Aug 2012 10:30:26 +0000 (12:30 +0200)
metze

libcli/smb/smbXcli_base.c
libcli/smb/smbXcli_base.h

index a363b4451c0991dba664a576cb52e85834e37672..66cb8732ec70813c7b5948e95af799a3f1b92224 100644 (file)
@@ -148,6 +148,7 @@ struct smbXcli_session {
 
        struct {
                uint16_t session_id;
+               DATA_BLOB application_key;
        } smb1;
 
        struct smb2cli_session *smb2;
@@ -4304,6 +4305,39 @@ void smb1cli_session_set_id(struct smbXcli_session *session,
        session->smb1.session_id = session_id;
 }
 
+NTSTATUS smb1cli_session_set_session_key(struct smbXcli_session *session,
+                                        const DATA_BLOB _session_key)
+{
+       struct smbXcli_conn *conn = session->conn;
+       uint8_t session_key[16];
+
+       if (conn == NULL) {
+               return NT_STATUS_INVALID_PARAMETER_MIX;
+       }
+
+       if (session->smb1.application_key.length != 0) {
+               return NT_STATUS_INVALID_PARAMETER_MIX;
+       }
+
+       if (_session_key.length == 0) {
+               return NT_STATUS_OK;
+       }
+
+       ZERO_STRUCT(session_key);
+       memcpy(session_key, _session_key.data,
+              MIN(_session_key.length, sizeof(session_key)));
+
+       session->smb1.application_key = data_blob_talloc(session,
+                                                        session_key,
+                                                        sizeof(session_key));
+       ZERO_STRUCT(session_key);
+       if (session->smb1.application_key.data == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       return NT_STATUS_OK;
+}
+
 uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
 {
        struct smbXcli_conn *conn = session->conn;
index c55bf53691de0ab337bf3da6c136895d8a4388d5..2f78247c603d9359f91f4a6ee649d6a8608e430e 100644 (file)
@@ -251,6 +251,8 @@ struct smbXcli_session *smbXcli_session_create(TALLOC_CTX *mem_ctx,
 uint16_t smb1cli_session_current_id(struct smbXcli_session* session);
 void smb1cli_session_set_id(struct smbXcli_session* session,
                            uint16_t session_id);
+NTSTATUS smb1cli_session_set_session_key(struct smbXcli_session *session,
+                                        const DATA_BLOB _session_key);
 uint8_t smb2cli_session_security_mode(struct smbXcli_session *session);
 uint64_t smb2cli_session_current_id(struct smbXcli_session *session);
 uint16_t smb2cli_session_get_flags(struct smbXcli_session *session);