s4:dsdb Use talloc_strndup() to ensure OIDs are null terminated
authorAndrew Bartlett <abartlet@samba.org>
Mon, 24 Aug 2009 10:22:18 +0000 (20:22 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 24 Aug 2009 10:24:19 +0000 (20:24 +1000)
The OIDs are not NULL terminated by the python caller, in line with
the LDB API, but we need them to be here, as we were casting them to a
string.

Andrew Bartlett

source4/dsdb/samdb/ldb_modules/schema_fsmo.c

index adc0fe41d049b0d5b130792aa48eef7019db9d16..c482ab57df2a19c844ea2a18d473320616f8b8d4 100644 (file)
@@ -172,8 +172,8 @@ static int schema_fsmo_add(struct ldb_module *module, struct ldb_request *req)
 {
        struct ldb_context *ldb;
        struct dsdb_schema *schema;
-       const char *attributeID = NULL;
-       const char *governsID = NULL;
+       const struct ldb_val *attributeID = NULL;
+       const struct ldb_val *governsID = NULL;
        const char *oid_attr = NULL;
        const char *oid = NULL;
        uint32_t id32;
@@ -202,21 +202,24 @@ static int schema_fsmo_add(struct ldb_module *module, struct ldb_request *req)
                return LDB_ERR_UNWILLING_TO_PERFORM;
        }
 
-       attributeID = samdb_result_string(req->op.add.message, "attributeID", NULL);
-       governsID = samdb_result_string(req->op.add.message, "governsID", NULL);
+       attributeID = ldb_msg_find_ldb_val(req->op.add.message, "attributeID");
+       governsID = ldb_msg_find_ldb_val(req->op.add.message, "governsID");
 
        if (attributeID) {
                oid_attr = "attributeID";
-               oid = attributeID;
+               oid = talloc_strndup(req, (const char *)attributeID->data, attributeID->length);
        } else if (governsID) {
                oid_attr = "governsID";
-               oid = governsID;
+               oid = talloc_strndup(req, (const char *)governsID->data, governsID->length);
+       } else {
+               return ldb_next_request(module, req);
        }
 
        if (!oid) {
-               return ldb_next_request(module, req);
+               ldb_oom(ldb);
+               return LDB_ERR_OPERATIONS_ERROR;
        }
-
+               
        status = dsdb_map_oid2int(schema, oid, &id32);
        if (W_ERROR_IS_OK(status)) {
                return ldb_next_request(module, req);