This should prevent all possible integer storage problems in future.
/*
add a uint64_t element to a record
*/
-static int add_uint64_element(struct ldb_message *msg, const char *attr, uint64_t v)
+static int add_uint64_element(struct ldb_context *ldb, struct ldb_message *msg,
+ const char *attr, uint64_t v)
{
struct ldb_message_element *el;
return 0;
}
- if (ldb_msg_add_fmt(msg, attr, "%llu", (unsigned long long)v) != 0) {
+ if (samdb_msg_add_uint64(ldb, msg, msg, attr, v) != LDB_SUCCESS) {
return -1;
}
* make sure this function is split and a callback is used */
ret = ldb_sequence_number(ldb, LDB_SEQ_NEXT, &seq_num);
if (ret == LDB_SUCCESS) {
- if (add_uint64_element(msg, "uSNCreated", seq_num) != 0 ||
- add_uint64_element(msg, "uSNChanged", seq_num) != 0) {
+ if (add_uint64_element(ldb, msg, "uSNCreated", seq_num) != 0 ||
+ add_uint64_element(ldb, msg, "uSNChanged", seq_num) != 0) {
return ldb_operr(ldb);
}
}
/* Get a sequence number from the backend */
ret = ldb_sequence_number(ldb, LDB_SEQ_NEXT, &seq_num);
if (ret == LDB_SUCCESS) {
- if (add_uint64_element(msg, "uSNChanged", seq_num) != 0) {
+ if (add_uint64_element(ldb, msg, "uSNChanged", seq_num) != 0) {
return ldb_operr(ldb);
}
}
/*
add a uint64_t element to a record
*/
-static int add_uint64_element(struct ldb_message *msg, const char *attr, uint64_t v)
+static int add_uint64_element(struct ldb_context *ldb, struct ldb_message *msg,
+ const char *attr, uint64_t v)
{
struct ldb_message_element *el;
+ int ret;
if (ldb_msg_find_element(msg, attr) != NULL) {
return LDB_SUCCESS;
}
- if (ldb_msg_add_fmt(msg, attr, "%llu", (unsigned long long)v) != LDB_SUCCESS) {
- return LDB_ERR_OPERATIONS_ERROR;
+ ret = samdb_msg_add_uint64(ldb, msg, msg, attr, v);
+ if (ret != LDB_SUCCESS) {
+ return ret;
}
el = ldb_msg_find_element(msg, attr);
return ret;
}
- if (add_uint64_element(msg, "uSNChanged", ac->seq_num) != LDB_SUCCESS) {
+ if (add_uint64_element(ldb, msg, "uSNChanged",
+ ac->seq_num) != LDB_SUCCESS) {
talloc_free(ac);
return ret;
}
return ret;
}
- if (add_uint64_element(msg, "uSNChanged", ac->seq_num) != LDB_SUCCESS) {
+ if (add_uint64_element(ldb, msg, "uSNChanged",
+ ac->seq_num) != LDB_SUCCESS) {
talloc_free(ac);
return ret;
}
return ldb_operr(ldb);
}
- if (add_uint64_element(msg, "uSNChanged", seq_num) != LDB_SUCCESS) {
+ if (add_uint64_element(ldb, msg, "uSNChanged",
+ seq_num) != LDB_SUCCESS) {
talloc_free(tmp_ctx);
return ldb_operr(ldb);
}
}
if (do_attribute(attrs, "domainFunctionality")) {
- if (ldb_msg_add_fmt(msg, "domainFunctionality",
- "%d", dsdb_functional_level(ldb)) != LDB_SUCCESS) {
+ if (samdb_msg_add_int(ldb, msg, msg, "domainFunctionality",
+ dsdb_functional_level(ldb)) != LDB_SUCCESS) {
goto failed;
}
}
if (do_attribute(attrs, "forestFunctionality")) {
- if (ldb_msg_add_fmt(msg, "forestFunctionality",
- "%d", dsdb_forest_functional_level(ldb)) != LDB_SUCCESS) {
+ if (samdb_msg_add_int(ldb, msg, msg, "forestFunctionality",
+ dsdb_forest_functional_level(ldb)) != LDB_SUCCESS) {
goto failed;
}
}
if (do_attribute(attrs, "domainControllerFunctionality")
&& (val = talloc_get_type(ldb_get_opaque(ldb, "domainControllerFunctionality"), int))) {
- if (ldb_msg_add_fmt(msg, "domainControllerFunctionality",
- "%d", *val) != LDB_SUCCESS) {
+ if (samdb_msg_add_int(ldb, msg, msg,
+ "domainControllerFunctionality",
+ *val) != LDB_SUCCESS) {
goto failed;
}
}
return ldb_module_oom(module);
}
- ret = ldb_msg_add_fmt(msg, "uSNHighest", "%llu", (unsigned long long)uSN);
+ ret = samdb_msg_add_uint64(ldb, msg, msg, "uSNHighest", uSN);
if (ret != LDB_SUCCESS) {
talloc_free(msg);
return ret;
/* urgent_uSN is optional so may not be stored */
if (urgent_uSN) {
- ret = ldb_msg_add_fmt(msg, "uSNUrgent", "%llu", (unsigned long long)urgent_uSN);
+ ret = samdb_msg_add_uint64(ldb, msg, msg, "uSNUrgent",
+ urgent_uSN);
if (ret != LDB_SUCCESS) {
talloc_free(msg);
return ret;
}
msg->dn = res->msgs[0]->dn;
- rtn = ldb_msg_add_fmt(msg, "msDS-SupportedEncryptionTypes",
- "%lu",
- (long unsigned int)(ENC_ALL_TYPES));
+ rtn = samdb_msg_add_uint(remote_ldb, msg, msg,
+ "msDS-SupportedEncryptionTypes", ENC_ALL_TYPES);
if (rtn != LDB_SUCCESS) {
r->out.error_string = NULL;
talloc_free(tmp_ctx);