#include "includes.h"
#include "lib/ldb/include/ldb.h"
+#include "lib/ldb/include/ldb_errors.h"
#include "lib/ldb/include/ldb_private.h"
#include "system/time.h"
#include "librpc/gen_ndr/ndr_security.h"
#define SAM_ACCOUNT_NAME_BASE "$000000-000000000000"
-static int samldb_search_bytree(struct ldb_module *module, const struct ldb_dn *base,
- enum ldb_scope scope, struct ldb_parse_tree *tree,
- const char * const *attrs, struct ldb_message ***res)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "samldb_search\n");
- return ldb_next_search_bytree(module, base, scope, tree, attrs, res);
-}
-
/*
allocate a new id, attempting to do it atomically
return 0 on failure, the id on success
const struct ldb_dn *dn, uint32_t *id)
{
const char * const attrs[2] = { "nextRid", NULL };
- struct ldb_message **res = NULL;
+ struct ldb_result *res = NULL;
struct ldb_message msg;
int ret;
const char *str;
struct ldb_message_element els[2];
ret = ldb_search(ldb, dn, LDB_SCOPE_BASE, "nextRid=*", attrs, &res);
- if (ret != 1) {
+ if (ret != LDB_SUCCESS || res->count != 1) {
if (res) talloc_free(res);
return -1;
}
- str = ldb_msg_find_string(res[0], "nextRid", NULL);
+ str = ldb_msg_find_string(res->msgs[0], "nextRid", NULL);
if (str == NULL) {
ldb_debug(ldb, LDB_DEBUG_FATAL, "attribute nextRid not found in %s\n", ldb_dn_linearize(res, dn));
talloc_free(res);
els[1].flags = LDB_FLAG_MOD_ADD;
els[1].name = els[0].name;
- vals[0].data = talloc_asprintf(mem_ctx, "%u", *id);
+ vals[0].data = (uint8_t *)talloc_asprintf(mem_ctx, "%u", *id);
if (!vals[0].data) {
return -1;
}
- vals[0].length = strlen(vals[0].data);
+ vals[0].length = strlen((char *)vals[0].data);
- vals[1].data = talloc_asprintf(mem_ctx, "%u", (*id)+1);
+ vals[1].data = (uint8_t *)talloc_asprintf(mem_ctx, "%u", (*id)+1);
if (!vals[1].data) {
return -1;
}
- vals[1].length = strlen(vals[1].data);
+ vals[1].length = strlen((char *)vals[1].data);
ret = ldb_modify(ldb, &msg);
if (ret != 0) {
{
TALLOC_CTX *local_ctx;
struct ldb_dn *sdn;
- struct ldb_message **res = NULL;
+ struct ldb_result *res = NULL;
int ret = 0;
- local_ctx = talloc_named(mem_ctx, 0, "samldb_search_domain memory conext");
+ local_ctx = talloc_new(mem_ctx);
if (local_ctx == NULL) return NULL;
sdn = ldb_dn_copy(local_ctx, dn);
do {
ret = ldb_search(module->ldb, sdn, LDB_SCOPE_BASE, "objectClass=domain", NULL, &res);
- talloc_free(res);
-
- if (ret == 1)
+ talloc_steal(local_ctx, res);
+ if (ret == LDB_SUCCESS && res->count == 1)
break;
-
} while ((sdn = ldb_dn_get_parent(local_ctx, sdn)));
- if (ret != 1) {
+ if (ret != LDB_SUCCESS || res->count != 1) {
talloc_free(local_ctx);
return NULL;
}
TALLOC_CTX *mem_ctx, const struct ldb_dn *obj_dn)
{
const char * const attrs[2] = { "objectSid", NULL };
- struct ldb_message **res = NULL;
+ struct ldb_result *res = NULL;
const struct ldb_dn *dom_dn;
uint32_t rid;
int ret;
/* find the domain sid */
ret = ldb_search(module->ldb, dom_dn, LDB_SCOPE_BASE, "objectSid=*", attrs, &res);
- if (ret != 1) {
+ if (ret != LDB_SUCCESS || res->count != 1) {
ldb_debug(module->ldb, LDB_DEBUG_FATAL, "samldb_get_new_sid: error retrieving domain sid!\n");
talloc_free(res);
return NULL;
}
- dom_sid = samdb_result_dom_sid(res, res[0], "objectSid");
+ dom_sid = samdb_result_dom_sid(res, res->msgs[0], "objectSid");
if (dom_sid == NULL) {
ldb_debug(module->ldb, LDB_DEBUG_FATAL, "samldb_get_new_sid: error retrieving domain sid!\n");
talloc_free(res);
return &msg->elements[i];
}
for (j = 0; j < msg->elements[i].num_values; j++) {
- if (strcasecmp(value, msg->elements[i].values[j].data) == 0) {
+ if (strcasecmp(value,
+ (char *)msg->elements[i].values[j].data) == 0) {
return &msg->elements[i];
}
}
return False;
}
- if (ldb_msg_add_string(module->ldb, msg, aname, aval) != 0) {
+ if (ldb_msg_add_string(msg, aname, aval) != 0) {
return False;
}
if (!NT_STATUS_IS_OK(status)) {
return -1;
}
- return (ldb_msg_add_value(module->ldb, msg, name, &v) == 0);
+ return (ldb_msg_add_value(msg, name, &v) == 0);
}
static BOOL samldb_find_or_add_attribute(struct ldb_module *module, struct ldb_message *msg, const char *name, const char *value, const char *set_value)
static int samldb_copy_template(struct ldb_module *module, struct ldb_message *msg, const char *filter)
{
- struct ldb_message **res, *t;
+ struct ldb_result *res;
+ struct ldb_message *t;
int ret, i, j;
/* pull the template record */
ret = ldb_search(module->ldb, NULL, LDB_SCOPE_SUBTREE, filter, NULL, &res);
- if (ret != 1) {
- ldb_debug(module->ldb, LDB_DEBUG_WARNING, "samldb: ERROR: template '%s' matched %d records\n", filter, ret);
+ if (ret != LDB_SUCCESS || res->count != 1) {
+ ldb_debug(module->ldb, LDB_DEBUG_WARNING, "samldb: ERROR: template '%s' matched too many records\n", filter);
return -1;
}
- t = res[0];
+ t = res->msgs[0];
for (i = 0; i < t->num_elements; i++) {
struct ldb_message_element *el = &t->elements[i];
}
if (samldb_find_attribute(msg, "objectclass", "computer") != NULL) {
- if (samldb_copy_template(module, msg2, "(&(CN=TemplateMemberServer)(objectclass=userTemplate))") != 0) {
+ if (samldb_copy_template(module, msg2, "(&(CN=TemplateServer)(objectclass=userTemplate))") != 0) {
ldb_debug(module->ldb, LDB_DEBUG_WARNING, "samldb_fill_user_or_computer_object: Error copying computer template!\n");
return NULL;
}
return NULL;
}
+ /*
+ useraccountcontrol: setting value 0 gives 0x200 for users
+ */
+
/* TODO: objectCategory, userAccountControl, badPwdCount, codePage, countryCode, badPasswordTime, lastLogoff, lastLogon, pwdLastSet, primaryGroupID, accountExpires, logonCount */
return msg2;
}
if ((attribute = samldb_find_attribute(msg2, "objectSid", NULL)) == NULL ) {
- struct dom_sid *sid = dom_sid_parse_talloc(msg2, rdn->value.data);
+ struct dom_sid *sid = dom_sid_parse_talloc(msg2, (char *)rdn->value.data);
if (sid == NULL) {
ldb_debug(module->ldb, LDB_DEBUG_FATAL, "samldb_fill_foreignSecurityPrincipal_object: internal error! Can't parse sid in CN\n");
return NULL;
}
/* add_record */
-static int samldb_add_record(struct ldb_module *module, const struct ldb_message *msg)
+static int samldb_add(struct ldb_module *module, struct ldb_request *req)
{
+ const struct ldb_message *msg = req->op.add.message;
struct ldb_message *msg2 = NULL;
int ret;
if (ldb_dn_is_special(msg->dn)) { /* do not manipulate our control entries */
- return ldb_next_add_record(module, msg);
+ return ldb_next_request(module, req);
}
/* is user or computer? add all relevant missing objects */
}
if (msg2) {
- ret = ldb_next_add_record(module, msg2);
+ req->op.add.message = msg2;
+ ret = ldb_next_request(module, req);
+ req->op.add.message = msg;
} else {
- ret = ldb_next_add_record(module, msg);
+ ret = ldb_next_request(module, req);
}
return ret;
}
-/* modify_record: change modifyTimestamp as well */
-static int samldb_modify_record(struct ldb_module *module, const struct ldb_message *msg)
+static int samldb_destructor(void *module_ctx)
{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "samldb_modify_record\n");
- return ldb_next_modify_record(module, msg);
+ /* struct ldb_module *ctx = module_ctx; */
+ /* put your clean-up functions here */
+ return 0;
}
-static int samldb_delete_record(struct ldb_module *module, const struct ldb_dn *dn)
+static int samldb_request(struct ldb_module *module, struct ldb_request *req)
{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "samldb_delete_record\n");
- return ldb_next_delete_record(module, dn);
-}
+ switch (req->operation) {
-static int samldb_rename_record(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "samldb_rename_record\n");
- return ldb_next_rename_record(module, olddn, newdn);
-}
+ case LDB_REQ_ADD:
+ return samldb_add(module, req);
-static int samldb_destructor(void *module_ctx)
-{
- /* struct ldb_module *ctx = module_ctx; */
- /* put your clean-up functions here */
- return 0;
+ default:
+ return ldb_next_request(module, req);
+
+ }
}
static const struct ldb_module_ops samldb_ops = {
.name = "samldb",
- .search_bytree = samldb_search_bytree,
- .add_record = samldb_add_record,
- .modify_record = samldb_modify_record,
- .delete_record = samldb_delete_record,
- .rename_record = samldb_rename_record
+ .request = samldb_request
};