]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s4:libcli: Add smb2_connect_enc_start()
authorAndreas Schneider <asn@samba.org>
Tue, 7 Jul 2020 10:44:26 +0000 (12:44 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Wed, 19 Aug 2020 16:22:43 +0000 (16:22 +0000)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source4/libcli/smb2/connect.c

index 95ff05eac8f32c007816613ddbe5cbd50a4648e3..3a3ecdf20e8d990058ea8ee04388af60afc0e7a8 100644 (file)
@@ -237,6 +237,7 @@ static void smb2_connect_session_start(struct tevent_req *req)
        tevent_req_set_callback(subreq, smb2_connect_session_done, req);
 }
 
+static void smb2_connect_enc_start(struct tevent_req *req);
 static void smb2_connect_tcon_start(struct tevent_req *req);
 static void smb2_connect_tcon_done(struct tevent_req *subreq);
 
@@ -289,6 +290,43 @@ static void smb2_connect_session_done(struct tevent_req *subreq)
                return;
        }
 
+       smb2_connect_enc_start(req);
+}
+
+static void smb2_connect_enc_start(struct tevent_req *req)
+{
+       struct smb2_connect_state *state =
+               tevent_req_data(req,
+                               struct smb2_connect_state);
+       enum smb_encryption_setting encryption_state =
+               cli_credentials_get_smb_encryption(state->credentials);
+       NTSTATUS status;
+
+       if (encryption_state < SMB_ENCRYPTION_DESIRED) {
+               smb2_connect_tcon_start(req);
+               return;
+       }
+
+       status = smb2cli_session_encryption_on(state->session->smbXcli);
+       if (!NT_STATUS_IS_OK(status)) {
+               if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
+                       if (encryption_state < SMB_ENCRYPTION_REQUIRED) {
+                               smb2_connect_tcon_start(req);
+                               return;
+                       }
+
+                       DBG_ERR("Encryption required and server doesn't support "
+                               "SMB3 encryption - failing connect\n");
+                       tevent_req_nterror(req, status);
+                       return;
+               }
+
+               DBG_ERR("Encryption required and setup failed with error %s.\n",
+                       nt_errstr(status));
+               tevent_req_nterror(req, NT_STATUS_PROTOCOL_NOT_SUPPORTED);
+               return;
+       }
+
        smb2_connect_tcon_start(req);
 }