From: Stefan Metzmacher Date: Wed, 5 Feb 2025 13:42:18 +0000 (+0100) Subject: libcli/lsarpc: add trust_forest_info_{from,to}_lsa2() X-Git-Tag: tevent-0.17.0~700 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c903d4699cc38397ecf49c503b126017bb21bb17;p=thirdparty%2Fsamba.git libcli/lsarpc: add trust_forest_info_{from,to}_lsa2() 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 Reviewed-by: Ralph Boehme --- diff --git a/libcli/lsarpc/util_lsarpc.c b/libcli/lsarpc/util_lsarpc.c index b8bb778f5a8..880b3d9d1d0 100644 --- a/libcli/lsarpc/util_lsarpc.c +++ b/libcli/lsarpc/util_lsarpc.c @@ -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, diff --git a/libcli/lsarpc/util_lsarpc.h b/libcli/lsarpc/util_lsarpc.h index b12ab4f4292..97b12ee67e6 100644 --- a/libcli/lsarpc/util_lsarpc.h +++ b/libcli/lsarpc/util_lsarpc.h @@ -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,