s4:ldb_ildap - Don't segfault on a empty RDN
[ira/wip.git] / source4 / lib / ldb / ldb_ildap / ldb_ildap.c
index 4447d0e09a473b8af1ca6983d73ff8d5f3394f0a..352b7696d698fa47492bfb6b93e2de4f54e1368f 100644 (file)
@@ -591,6 +591,8 @@ static int ildb_rename(struct ildb_context *ac)
 {
        struct ldb_request *req = ac->req;
        struct ldap_message *msg;
+       const char *rdn_name;
+       const struct ldb_val *rdn_val;
 
        msg = new_ldap_message(req);
        if (msg == NULL) {
@@ -604,10 +606,16 @@ static int ildb_rename(struct ildb_context *ac)
                return LDB_ERR_INVALID_DN_SYNTAX;
        }
 
-       msg->r.ModifyDNRequest.newrdn =
-               talloc_asprintf(msg, "%s=%s",
-                               ldb_dn_get_rdn_name(req->op.rename.newdn),
-                               ldb_dn_escape_value(msg, *ldb_dn_get_rdn_val(req->op.rename.newdn)));
+       rdn_name = ldb_dn_get_rdn_name(req->op.rename.newdn);
+       rdn_val = ldb_dn_get_rdn_val(req->op.rename.newdn);
+
+       if ((rdn_name != NULL) && (rdn_val != NULL)) {
+               msg->r.ModifyDNRequest.newrdn =
+                       talloc_asprintf(msg, "%s=%s", rdn_name,
+                               ldb_dn_escape_value(msg, *rdn_val));
+       } else {
+               msg->r.ModifyDNRequest.newrdn = talloc_strdup(msg, "");
+       }
        if (msg->r.ModifyDNRequest.newrdn == NULL) {
                talloc_free(msg);
                return LDB_ERR_OPERATIONS_ERROR;
@@ -790,7 +798,7 @@ static int ildb_connect(struct ldb_context *ldb, const char *url,
 
        status = ldap_connect(ildb->ldap, url);
        if (!NT_STATUS_IS_OK(status)) {
-               ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to connect to ldap URL '%s' - %s\n",
+               ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to connect to ldap URL '%s' - %s",
                          url, ldap_errstr(ildb->ldap, module, status));
                goto failed;
        }
@@ -810,14 +818,14 @@ static int ildb_connect(struct ldb_context *ldb, const char *url,
                        const char *password = cli_credentials_get_password(creds);
                        status = ldap_bind_simple(ildb->ldap, bind_dn, password);
                        if (!NT_STATUS_IS_OK(status)) {
-                               ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to bind - %s\n",
+                               ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to bind - %s",
                                          ldap_errstr(ildb->ldap, module, status));
                                goto failed;
                        }
                } else {
                        status = ldap_bind_sasl(ildb->ldap, creds, lp_ctx);
                        if (!NT_STATUS_IS_OK(status)) {
-                               ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to bind - %s\n",
+                               ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to bind - %s",
                                          ldap_errstr(ildb->ldap, module, status));
                                goto failed;
                        }