]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
librpc: Simplify dcerpc_is_transport_encrypted()
authorVolker Lendecke <vl@samba.org>
Tue, 18 Apr 2023 10:04:17 +0000 (12:04 +0200)
committerVolker Lendecke <vl@samba.org>
Tue, 16 May 2023 10:53:40 +0000 (10:53 +0000)
Simplify logic by using security_token_count_flag_sids()

Bug: https://bugzilla.samba.org/show_bug.cgi?id=15361
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
librpc/rpc/dcerpc_helper.c

index cf0deeb20794ba3a5b1a3118b9470f6225276884..eec78e034eec81f17d702da547e5796d8bde583d 100644 (file)
@@ -20,6 +20,7 @@
 #include "librpc/gen_ndr/auth.h"
 #include "lib/crypto/gnutls_helpers.h"
 #include "libcli/security/dom_sid.h"
+#include "libcli/security/security_token.h"
 #include "libcli/smb/smb2_constants.h"
 
 #include "dcerpc_helper.h"
@@ -75,23 +76,17 @@ bool dcerpc_is_transport_encrypted(struct auth_session_info *session_info)
        uint16_t dialect = 0;
        uint16_t encrypt = 0;
        uint16_t cipher = 0;
-       uint32_t i;
+       size_t num_smb3_sids;
        bool ok;
 
-       for (i = 0; i < token->num_sids; i++) {
-               int cmp;
-
-               /* There is only one SMB3 SID allowed! */
-               cmp = dom_sid_compare_domain(&token->sids[i], &smb3_dom_sid);
-               if (cmp == 0) {
-                       if (smb3_sid == NULL) {
-                               smb3_sid = &token->sids[i];
-                       } else {
-                               DBG_ERR("ERROR: The SMB3 SID has been detected "
-                                       "multiple times\n");
-                               return false;
-                       }
-               }
+       num_smb3_sids = security_token_count_flag_sids(token,
+                                                      &smb3_dom_sid,
+                                                      3,
+                                                      &smb3_sid);
+       if (num_smb3_sids > 1) {
+               DBG_ERR("ERROR: The SMB3 SID has been detected %zu times\n",
+                       num_smb3_sids);
+               return false;
        }
 
        if (smb3_sid == NULL) {