]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
libcli/lsarpc: add trust_forest_info_tln[_ex]_match()
authorStefan Metzmacher <metze@samba.org>
Tue, 5 Jun 2018 01:36:39 +0000 (03:36 +0200)
committerRalph Boehme <slow@samba.org>
Sat, 22 Feb 2025 16:00:36 +0000 (16:00 +0000)
These are copies of dsdb_trust_find_tln[_ex]_match()
in source4/dsdb/common/util_trusts.c, which gets replaced
in the next commits.

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 018bbcc0eec91d0eb75693d9fb6701f239222030..05126304758b4937062c7c88fb14807ab5da7ec1 100644 (file)
@@ -18,6 +18,7 @@
 */
 
 #include "includes.h"
+#include "lib/util/dns_cmp.h"
 #include "../librpc/gen_ndr/ndr_drsblobs.h"
 #include "../librpc/gen_ndr/ndr_lsa.h"
 #include "libcli/lsarpc/util_lsarpc.h"
@@ -587,3 +588,88 @@ NTSTATUS trust_forest_info_to_lsa(TALLOC_CTX *mem_ctx,
        *_lfti = lfti;
        return NT_STATUS_OK;
 }
+
+static int trust_forest_info_tln_match_internal(
+               const struct lsa_ForestTrustInformation *info,
+               enum lsa_ForestTrustRecordType type,
+               uint32_t disable_mask,
+               const char *tln)
+{
+       uint32_t i;
+
+       for (i = 0; i < info->count; i++) {
+               struct lsa_ForestTrustRecord *e = info->entries[i];
+               struct lsa_StringLarge *t = NULL;
+               int cmp;
+
+               if (e == NULL) {
+                       continue;
+               }
+
+               if (e->type != type) {
+                       continue;
+               }
+
+               if (e->flags & disable_mask) {
+                       continue;
+               }
+
+               switch (type) {
+               case LSA_FOREST_TRUST_TOP_LEVEL_NAME:
+                       t = &e->forest_trust_data.top_level_name;
+                       break;
+               case LSA_FOREST_TRUST_TOP_LEVEL_NAME_EX:
+                       t = &e->forest_trust_data.top_level_name_ex;
+                       break;
+               default:
+                       break;
+               }
+
+               if (t == NULL) {
+                       continue;
+               }
+
+               cmp = dns_cmp(tln, t->string);
+               switch (cmp) {
+               case DNS_CMP_MATCH:
+               case DNS_CMP_FIRST_IS_CHILD:
+                       return i;
+               }
+       }
+
+       return -1;
+}
+
+bool trust_forest_info_tln_match(
+               const struct lsa_ForestTrustInformation *info,
+               const char *tln)
+{
+       int m;
+
+       m = trust_forest_info_tln_match_internal(info,
+                                       LSA_FOREST_TRUST_TOP_LEVEL_NAME,
+                                       LSA_TLN_DISABLED_MASK,
+                                       tln);
+       if (m != -1) {
+               return true;
+       }
+
+       return false;
+}
+
+bool trust_forest_info_tln_ex_match(
+               const struct lsa_ForestTrustInformation *info,
+               const char *tln)
+{
+       int m;
+
+       m = trust_forest_info_tln_match_internal(info,
+                                       LSA_FOREST_TRUST_TOP_LEVEL_NAME_EX,
+                                       0,
+                                       tln);
+       if (m != -1) {
+               return true;
+       }
+
+       return false;
+}
index 6795c148357201c17e02b50acd9c91462b78f2e3..b12ab4f42929fab266da8e4c62b92992643f6e34 100644 (file)
@@ -46,4 +46,10 @@ NTSTATUS trust_forest_info_to_lsa(TALLOC_CTX *mem_ctx,
                                  const struct ForestTrustInfo *fti,
                                  struct lsa_ForestTrustInformation **_lfti);
 
+bool trust_forest_info_tln_match(
+               const struct lsa_ForestTrustInformation *info,
+               const char *tln);
+bool trust_forest_info_tln_ex_match(
+               const struct lsa_ForestTrustInformation *info,
+               const char *tln);
 #endif /* _LIBCLI_AUTH_UTIL_LSARPC_H_ */