]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib/ldb: let ldb_ldif_parse_modrdn() handle names without 'rdn_name=' prefix
authorStefan Metzmacher <metze@samba.org>
Thu, 23 Feb 2023 13:56:39 +0000 (14:56 +0100)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 22 Mar 2023 22:10:32 +0000 (22:10 +0000)
This is needed in order to process schema updates.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
lib/ldb/common/ldb_ldif.c

index 6f7589fef68ecf2eef8896628c2e6c34368c9cf6..fc9a4fd0939945a60ecc718f4fa9f40fb0bd814a 100644 (file)
@@ -584,6 +584,7 @@ int ldb_ldif_parse_modrdn(struct ldb_context *ldb,
                          struct ldb_dn **_newdn)
 {
        struct ldb_message *msg = ldif->msg;
+       struct ldb_val _newrdn_val = {};
        struct ldb_val *newrdn_val = NULL;
        struct ldb_val *deleteoldrdn_val = NULL;
        struct ldb_val *newsuperior_val = NULL;
@@ -667,6 +668,25 @@ int ldb_ldif_parse_modrdn(struct ldb_context *ldb,
                goto err_op;
        }
 
+       if (newrdn_val->length != 0 && strchr((const char *)newrdn_val->data, '=') == NULL) {
+               const char *rdn_name = ldb_dn_get_rdn_name(olddn);
+               char *new_rdn = NULL;
+
+               new_rdn = talloc_asprintf(tmp_ctx,
+                                         "%s=%s",
+                                         rdn_name,
+                                         (const char *)newrdn_val->data);
+               if (new_rdn == NULL) {
+                       ldb_debug(ldb, LDB_DEBUG_ERROR,
+                                 "Error: failed to allocate '%s=%s'",
+                                 rdn_name, (char *)newrdn_val->data);
+                       goto err_op;
+               }
+               _newrdn_val.data = (uint8_t *)new_rdn;
+               _newrdn_val.length = strlen(new_rdn);
+               newrdn_val = &_newrdn_val;
+       }
+
        newrdn = ldb_dn_from_ldb_val(tmp_ctx, ldb, newrdn_val);
        if (!ldb_dn_validate(newrdn)) {
                ldb_debug(ldb, LDB_DEBUG_ERROR,