]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
libcli/lsarpc: add trust_forest_info_{from,to}_lsa2()
authorStefan Metzmacher <metze@samba.org>
Wed, 5 Feb 2025 13:42:18 +0000 (14:42 +0100)
committerRalph Boehme <slow@samba.org>
Sat, 22 Feb 2025 16:00:36 +0000 (16:00 +0000)
Note for now these will fail for FOREST_TRUST_BINARY_DATA and
FOREST_TRUST_SCANNER_INFO.

But this will still make the transition from
lsa_ForestTrustInformation to lsa_ForestTrustInformation2
easier.

Support for will FOREST_TRUST_BINARY_DATA and FOREST_TRUST_SCANNER_INFO
will be added before we implement the forest trust background scanner
job and the lsaRSetForestTrustInformation2 function.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
libcli/lsarpc/util_lsarpc.c
libcli/lsarpc/util_lsarpc.h

index b8bb778f5a8357bcb8a9c785c6aee8f58b4384c9..880b3d9d1d02bdcb4353076e3d11654c68f3aff1 100644 (file)
@@ -723,6 +723,100 @@ NTSTATUS trust_forest_info_to_lsa(TALLOC_CTX *mem_ctx,
        return NT_STATUS_OK;
 }
 
+NTSTATUS trust_forest_info_from_lsa2(TALLOC_CTX *mem_ctx,
+                               const struct lsa_ForestTrustInformation2 *lfti,
+                               struct ForestTrustInfo **_fti)
+{
+       struct ForestTrustInfo *fti;
+       uint32_t i;
+
+       *_fti = NULL;
+
+       fti = talloc_zero(mem_ctx, struct ForestTrustInfo);
+       if (fti == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       fti->version = 1;
+       fti->count = lfti->count;
+       fti->records = talloc_zero_array(fti,
+                                        struct ForestTrustInfoRecordArmor,
+                                        fti->count);
+       if (fti->records == NULL) {
+               TALLOC_FREE(fti);
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       for (i = 0; i < fti->count; i++) {
+               const struct lsa_ForestTrustRecord2 *lftr2 = lfti->entries[i];
+               struct ForestTrustInfoRecord *ftr = &fti->records[i].record;
+               NTSTATUS status;
+
+               status = trust_forest_record_from_lsa(fti->records,
+                                                     lftr2,
+                                                     ftr);
+               if (!NT_STATUS_IS_OK(status)) {
+                       TALLOC_FREE(fti);
+                       return status;
+               }
+       }
+
+       *_fti = fti;
+       return NT_STATUS_OK;
+}
+
+NTSTATUS trust_forest_info_to_lsa2(TALLOC_CTX *mem_ctx,
+                                  const struct ForestTrustInfo *fti,
+                                  struct lsa_ForestTrustInformation2 **_lfti)
+{
+       struct lsa_ForestTrustInformation2 *lfti;
+       uint32_t i;
+
+       *_lfti = NULL;
+
+       if (fti->version != 1) {
+               return NT_STATUS_INVALID_PARAMETER;
+       }
+
+       lfti = talloc_zero(mem_ctx, struct lsa_ForestTrustInformation2);
+       if (lfti == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       lfti->count = fti->count;
+       lfti->entries = talloc_zero_array(mem_ctx,
+                                         struct lsa_ForestTrustRecord2 *,
+                                         lfti->count);
+       if (lfti->entries == NULL) {
+               TALLOC_FREE(lfti);
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       for (i = 0; i < fti->count; i++) {
+               struct ForestTrustInfoRecord *ftr = &fti->records[i].record;
+               struct lsa_ForestTrustRecord2 *lftr2 = NULL;
+               NTSTATUS status;
+
+               lftr2 = talloc_zero(lfti->entries,
+                                   struct lsa_ForestTrustRecord2);
+               if (lftr2 == NULL) {
+                       TALLOC_FREE(lfti);
+                       return NT_STATUS_NO_MEMORY;
+               }
+
+               status = trust_forest_record_to_lsa(lftr2, ftr, lftr2);
+               if (!NT_STATUS_IS_OK(status)) {
+                       TALLOC_FREE(lfti);
+                       return NT_STATUS_NO_MEMORY;
+               }
+
+               lfti->entries[i] = lftr2;
+       }
+
+       *_lfti = lfti;
+       return NT_STATUS_OK;
+}
+
 static int trust_forest_info_tln_match_internal(
                const struct lsa_ForestTrustInformation *info,
                enum lsa_ForestTrustRecordType type,
index b12ab4f42929fab266da8e4c62b92992643f6e34..97b12ee67e695ec83426c9e5f5808936e0a54176 100644 (file)
@@ -26,6 +26,7 @@ struct lsa_TrustDomainInfoBuffer;
 struct trustAuthInOutBlob;
 struct ForestTrustInfo;
 struct lsa_ForestTrustInformation;
+struct lsa_ForestTrustInformation2;
 
 NTSTATUS auth_blob_2_auth_info(TALLOC_CTX *mem_ctx,
                               DATA_BLOB incoming, DATA_BLOB outgoing,
@@ -45,6 +46,12 @@ NTSTATUS trust_forest_info_from_lsa(TALLOC_CTX *mem_ctx,
 NTSTATUS trust_forest_info_to_lsa(TALLOC_CTX *mem_ctx,
                                  const struct ForestTrustInfo *fti,
                                  struct lsa_ForestTrustInformation **_lfti);
+NTSTATUS trust_forest_info_from_lsa2(TALLOC_CTX *mem_ctx,
+                               const struct lsa_ForestTrustInformation2 *lfti,
+                               struct ForestTrustInfo **_fti);
+NTSTATUS trust_forest_info_to_lsa2(TALLOC_CTX *mem_ctx,
+                                  const struct ForestTrustInfo *fti,
+                                  struct lsa_ForestTrustInformation2 **_lfti);
 
 bool trust_forest_info_tln_match(
                const struct lsa_ForestTrustInformation *info,