From f02a4002d5c3cfcd7f36b3bcf13310ffd155de90 Mon Sep 17 00:00:00 2001 From: =?utf8?q?G=C3=BCnther=20Deschner?= Date: Tue, 14 Jan 2025 01:40:05 +0100 Subject: [PATCH] s3-libads: dump ADS_MODSLIST before attempting the LDAP modify BUG: https://bugzilla.samba.org/show_bug.cgi?id=15777 Guenther Signed-off-by: Guenther Deschner Reviewed-by: Andreas Schneider --- source3/libads/ldap.c | 66 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c index 48c5b263ff9..e30f84e3ffb 100644 --- a/source3/libads/ldap.c +++ b/source3/libads/ldap.c @@ -1966,6 +1966,67 @@ static ADS_STATUS ads_modlist_add(TALLOC_CTX *ctx, ADS_MODLIST *mods, return ADS_ERROR(LDAP_SUCCESS); } +/* + dump a ADS_MODSLIST via DEBUG +*/ +static void ads_dump_modlist(ADS_MODLIST *mods) +{ + LDAPMod **modlist = (LDAPMod **)*mods; + const char *op = NULL; + size_t i, j; + char *buf = NULL; + + if (mods == NULL || DEBUGLEVEL < DBGLVL_DEBUG) { + return; + } + + buf = talloc_strdup(talloc_tos(), ""); + + for (i = 0; modlist[i] != NULL; i++) { + + /* only ever used three ops */ + + switch (modlist[i]->mod_op) { + case LDAP_MOD_DELETE: + op = "LDAP_MOD_DELETE"; + break; + case LDAP_MOD_REPLACE: + op = "LDAP_MOD_REPLACE"; + break; + case LDAP_MOD_REPLACE | LDAP_MOD_BVALUES: + op = "LDAP_MOD_REPLACE | LDAP_MOD_BVALUES"; + break; + default: + op = "unknown"; + break; + } + + talloc_asprintf_addbuf(&buf, "mod[%zu]: mod_op: %s\n", i, op); + talloc_asprintf_addbuf(&buf, + "mod[%zu]: mod_type: %s\n", + i, + modlist[i]->mod_type); + + if (modlist[i]->mod_op & LDAP_MOD_BVALUES) { + continue; + } + + for (j = 0; modlist[i]->mod_values[j] != NULL; j++) { + talloc_asprintf_addbuf( + &buf, + "mod[%zu]: mod_values[%zu]: %s\n", + i, + j, + modlist[i]->mod_values[j]); + } + } + + if (buf != NULL) { + DBG_DEBUG("%s", buf); + TALLOC_FREE(buf); + } +} + /** * Add a single string value to a mod list * @param ctx An initialized TALLOC_CTX @@ -2073,6 +2134,9 @@ ADS_STATUS ads_gen_mod(ADS_STRUCT *ads, const char *mod_dn, ADS_MODLIST mods) for(i=0;(mods[i]!=0)&&(mods[i]!=(LDAPMod *) -1);i++); /* make sure the end of the list is NULL */ mods[i] = NULL; + + ads_dump_modlist(&mods); + ret = ldap_modify_ext_s(ads->ldap.ld, utf8_dn, (LDAPMod **) mods, controls, NULL); ads_print_error(ret, ads->ldap.ld); @@ -2105,6 +2169,8 @@ ADS_STATUS ads_gen_add(ADS_STRUCT *ads, const char *new_dn, ADS_MODLIST mods) /* make sure the end of the list is NULL */ mods[i] = NULL; + ads_dump_modlist(&mods); + ret = ldap_add_ext_s(ads->ldap.ld, utf8_dn, (LDAPMod**)mods, NULL, NULL); ads_print_error(ret, ads->ldap.ld); TALLOC_FREE(utf8_dn); -- 2.47.2