s4-ldb: better to test for valid arguments in ldb library than commandline
authorAndrew Tridgell <tridge@samba.org>
Fri, 27 Nov 2009 03:18:39 +0000 (14:18 +1100)
committerAndrew Tridgell <tridge@samba.org>
Fri, 27 Nov 2009 05:05:06 +0000 (16:05 +1100)
We were testing for valid DNs in ldbrename in the command line
tool. This hid a bug in the ldb library where we caught a bad DN in
the objectclass module rather than in the main ldb code. It is better
to do validation of the DNs passed on the command line in the library
code, as this gives us more consistent error handling between the
programming APIs for ldb and the command line.

source4/lib/ldb/common/ldb.c
source4/lib/ldb/tools/ldbrename.c

index 3a8023ac93b0a097e8a733735a57ead6be0a3c74..94a5fb2153d7a3b73833411fd31ffdba5db8a16e 100644 (file)
@@ -791,6 +791,16 @@ int ldb_request(struct ldb_context *ldb, struct ldb_request *req)
                ret = module->ops->del(module, req);
                break;
        case LDB_RENAME:
+               if (!ldb_dn_validate(req->op.rename.olddn)) {
+                       ldb_asprintf_errstring(ldb, "ldb_rename: invalid olddn '%s'",
+                                              ldb_dn_get_linearized(req->op.rename.olddn));
+                       return LDB_ERR_INVALID_DN_SYNTAX;
+               }
+               if (!ldb_dn_validate(req->op.rename.newdn)) {
+                       ldb_asprintf_errstring(ldb, "ldb_rename: invalid newdn '%s'",
+                                              ldb_dn_get_linearized(req->op.rename.newdn));
+                       return LDB_ERR_INVALID_DN_SYNTAX;
+               }
                FIRST_OP(ldb, rename);
                ret = module->ops->rename(module, req);
                break;
index fcae766a2019700e4e9ab895199e4566f00486ce..bfccacc2066d70214bd68c7ef64538180b731abd 100644 (file)
@@ -63,15 +63,6 @@ int main(int argc, const char **argv)
        dn1 = ldb_dn_new(ldb, ldb, options->argv[0]);
        dn2 = ldb_dn_new(ldb, ldb, options->argv[1]);
 
-       if ( ! ldb_dn_validate(dn1)) {
-               printf("Invalid DN1: %s\n", options->argv[0]);
-               return -1;
-       }
-       if ( ! ldb_dn_validate(dn2)) {
-               printf("Invalid DN2: %s\n", options->argv[1]);
-               return -1;
-       }
-
        ret = ldb_rename(ldb, dn1, dn2);
        if (ret == 0) {
                printf("Renamed 1 record\n");