libcli/security: Move dup_nt_token() to libcli/security
authorAndrew Bartlett <abartlet@samba.org>
Fri, 15 Sep 2023 05:31:44 +0000 (17:31 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 26 Sep 2023 23:45:36 +0000 (23:45 +0000)
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
libcli/security/security_token.c
libcli/security/security_token.h
source3/include/proto.h
source3/lib/util_nttoken.c

index 95bf68e8e24f1f36fbc2d3f6e2f1bcb9d7b68852..1c76b921e951c4a78fff55a4b86267fb618dd483 100644 (file)
@@ -29,6 +29,7 @@
 #include "libcli/security/security_token.h"
 #include "libcli/security/dom_sid.h"
 #include "libcli/security/privileges.h"
+#include "librpc/gen_ndr/ndr_security.h"
 
 /*
   return a blank security token
@@ -43,6 +44,61 @@ struct security_token *security_token_initialise(TALLOC_CTX *mem_ctx,
        return st;
 }
 
+/****************************************************************************
+ Duplicate a SID token.
+****************************************************************************/
+
+struct security_token *dup_nt_token(TALLOC_CTX *mem_ctx, const struct security_token *src)
+{
+       TALLOC_CTX *frame = NULL;
+       struct security_token *dst = NULL;
+       DATA_BLOB blob;
+       enum ndr_err_code ndr_err;
+
+       if (src == NULL) {
+               return NULL;
+       }
+
+       frame = talloc_stackframe();
+
+       ndr_err = ndr_push_struct_blob(
+               &blob,
+               frame,
+               src,
+               (ndr_push_flags_fn_t)ndr_push_security_token);
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+               DBG_ERR("Failed to duplicate security_token ndr_push_security_token failed: %s\n",
+                       ndr_errstr(ndr_err));
+               TALLOC_FREE(frame);
+               return NULL;
+       }
+
+       dst = talloc_zero(mem_ctx, struct security_token);
+       if (dst == NULL) {
+               DBG_ERR("talloc failed\n");
+               TALLOC_FREE(frame);
+               return NULL;
+       }
+
+       ndr_err = ndr_pull_struct_blob(
+               &blob,
+               dst,
+               dst,
+               (ndr_pull_flags_fn_t)ndr_pull_security_token);
+
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+               DBG_ERR("Failed to duplicate security_token ndr_pull_security_token "
+                       "failed: %s\n",
+                       ndr_errstr(ndr_err));
+               TALLOC_FREE(dst);
+               TALLOC_FREE(frame);
+               return NULL;
+       }
+
+       TALLOC_FREE(frame);
+       return dst;
+}
+
 /****************************************************************************
  prints a struct security_token to debug output.
 ****************************************************************************/
index 1c9b24028534b1ccf94591b75e9016ff39481fac..f2ff1b84b840d85f9feced990c1aebebf87c8b13 100644 (file)
@@ -39,6 +39,8 @@
 struct security_token *security_token_initialise(TALLOC_CTX *mem_ctx,
                                                 enum claims_evaluation_control evaluate_claims);
 
+struct security_token *dup_nt_token(TALLOC_CTX *mem_ctx, const struct security_token *ptoken);
+
 /****************************************************************************
  prints a struct security_token to debug output.
 ****************************************************************************/
index 5dd35c3c0dfc65c9ebdc7423bb0e162f3f8d891b..20c9ad8cd2f5981acc4b32580f4fa368ebe64b06 100644 (file)
@@ -394,7 +394,6 @@ void smb_nscd_flush_group_cache(void);
 
 /* The following definitions come from lib/util_nttoken.c  */
 
-struct security_token *dup_nt_token(TALLOC_CTX *mem_ctx, const struct security_token *ptoken);
 NTSTATUS merge_nt_token(TALLOC_CTX *mem_ctx,
                        const struct security_token *token_1,
                        const struct security_token *token_2,
index 581ab3dabe712202ff34027030d394c322cd9ed3..af9ce37c43e1885620e8d10d7c33cea2a68a9d7b 100644 (file)
 
 #include "includes.h"
 #include "../libcli/security/security.h"
-#include "librpc/gen_ndr/ndr_security.h"
-
-/****************************************************************************
- Duplicate a SID token.
-****************************************************************************/
-
-struct security_token *dup_nt_token(TALLOC_CTX *mem_ctx, const struct security_token *src)
-{
-       TALLOC_CTX *frame = NULL;
-       struct security_token *dst = NULL;
-       DATA_BLOB blob;
-       enum ndr_err_code ndr_err;
-
-       if (src == NULL) {
-               return NULL;
-       }
-
-       frame = talloc_stackframe();
-
-       ndr_err = ndr_push_struct_blob(
-               &blob,
-               frame,
-               src,
-               (ndr_push_flags_fn_t)ndr_push_security_token);
-       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
-               DBG_ERR("Failed to duplicate security_token ndr_push_security_token failed: %s\n",
-                       ndr_errstr(ndr_err));
-               TALLOC_FREE(frame);
-               return NULL;
-       }
-
-       dst = talloc_zero(mem_ctx, struct security_token);
-       if (dst == NULL) {
-               DBG_ERR("talloc failed\n");
-               TALLOC_FREE(frame);
-               return NULL;
-       }
-
-       ndr_err = ndr_pull_struct_blob(
-               &blob,
-               dst,
-               dst,
-               (ndr_pull_flags_fn_t)ndr_pull_security_token);
-
-       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
-               DBG_ERR("Failed to duplicate security_token ndr_pull_security_token "
-                       "failed: %s\n",
-                       ndr_errstr(ndr_err));
-               TALLOC_FREE(dst);
-               TALLOC_FREE(frame);
-               return NULL;
-       }
-
-       TALLOC_FREE(frame);
-       return dst;
-}
 
 /****************************************************************************
  merge NT tokens