1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

r4475: fixed smbd to work with the small changes in the ldb API (the most important

change was in the ldb_msg_add_*() routines, which now use the msg as a context,
and thus it needs to be a talloc ptr)
This commit is contained in:
Andrew Tridgell 2005-01-02 07:51:13 +00:00 committed by Gerald (Jerry) Carter
parent 0ab98f50a7
commit 1a4713bfd0
10 changed files with 194 additions and 153 deletions

View File

@ -33,6 +33,7 @@ sub smb_build_main($)
"lib/dcom/config.mk",
"lib/socket/config.mk",
"lib/ldb/config.mk",
"lib/talloc/config.mk",
"lib/tdb/config.mk",
"lib/registry/config.mk",
"lib/messaging/config.mk",

View File

@ -104,7 +104,6 @@ int samdb_search_free(void *ctx,
TALLOC_CTX *mem_ctx, struct ldb_message **res)
{
struct ldb_wrap *sam_ctx = ctx;
ldb_set_alloc(sam_ctx->ldb, talloc_realloc_fn, mem_ctx);
return ldb_search_free(sam_ctx->ldb, res);
}
@ -733,7 +732,6 @@ int samdb_msg_add_string(void *ctx, TALLOC_CTX *mem_ctx, struct ldb_message *msg
if (s == NULL || a == NULL) {
return -1;
}
ldb_set_alloc(sam_ctx->ldb, talloc_realloc_fn, mem_ctx);
return ldb_msg_add_string(sam_ctx->ldb, msg, a, s);
}
@ -748,7 +746,6 @@ int samdb_msg_add_delete(void *ctx, TALLOC_CTX *mem_ctx, struct ldb_message *msg
if (a == NULL) {
return -1;
}
ldb_set_alloc(sam_ctx->ldb, talloc_realloc_fn, mem_ctx);
/* we use an empty replace rather than a delete, as it allows for
samdb_replace() to be used everywhere */
return ldb_msg_add_empty(sam_ctx->ldb, msg, a, LDB_FLAG_MOD_REPLACE);
@ -770,7 +767,6 @@ int samdb_msg_add_addval(void *ctx, TALLOC_CTX *mem_ctx, struct ldb_message *msg
v = talloc_strdup(mem_ctx, value);
if (v == NULL)
return -1;
ldb_set_alloc(sam_ctx->ldb, talloc_realloc_fn, mem_ctx);
ret = ldb_msg_add_string(sam_ctx->ldb, msg, a, v);
if (ret != 0)
return ret;
@ -797,7 +793,6 @@ int samdb_msg_add_delval(void *ctx, TALLOC_CTX *mem_ctx, struct ldb_message *msg
v = talloc_strdup(mem_ctx, value);
if (v == NULL)
return -1;
ldb_set_alloc(sam_ctx->ldb, talloc_realloc_fn, mem_ctx);
ret = ldb_msg_add_string(sam_ctx->ldb, msg, a, v);
if (ret != 0)
return ret;
@ -852,7 +847,6 @@ int samdb_msg_add_hash(void *ctx, TALLOC_CTX *mem_ctx, struct ldb_message *msg,
return -1;
}
memcpy(val.data, hash.hash, 16);
ldb_set_alloc(sam_ctx->ldb, talloc_realloc_fn, mem_ctx);
return ldb_msg_add_value(sam_ctx->ldb, msg, attr_name, &val);
}
@ -873,7 +867,6 @@ int samdb_msg_add_hashes(void *ctx, TALLOC_CTX *mem_ctx, struct ldb_message *msg
for (i=0;i<count;i++) {
memcpy(i*16 + (char *)val.data, hashes[i].hash, 16);
}
ldb_set_alloc(sam_ctx->ldb, talloc_realloc_fn, mem_ctx);
return ldb_msg_add_value(sam_ctx->ldb, msg, attr_name, &val);
}
@ -896,7 +889,6 @@ int samdb_msg_add_logon_hours(void *ctx, TALLOC_CTX *mem_ctx, struct ldb_message
struct ldb_val val;
val.length = hours->units_per_week / 8;
val.data = hours->bitmap;
ldb_set_alloc(sam_ctx->ldb, talloc_realloc_fn, mem_ctx);
return ldb_msg_add_value(sam_ctx->ldb, msg, attr_name, &val);
}
@ -906,11 +898,8 @@ int samdb_msg_add_logon_hours(void *ctx, TALLOC_CTX *mem_ctx, struct ldb_message
int samdb_msg_set_string(void *ctx, TALLOC_CTX *mem_ctx, struct ldb_message *msg,
const char *attr_name, const char *str)
{
struct ldb_wrap *sam_ctx = ctx;
struct ldb_message_element *el;
ldb_set_alloc(sam_ctx->ldb, talloc_realloc_fn, mem_ctx);
el = ldb_msg_find_element(msg, attr_name);
if (el) {
el->num_values = 0;
@ -938,7 +927,6 @@ int samdb_add(void *ctx, TALLOC_CTX *mem_ctx, struct ldb_message *msg)
{
struct ldb_wrap *sam_ctx = ctx;
ldb_set_alloc(sam_ctx->ldb, talloc_realloc_fn, mem_ctx);
return ldb_add(sam_ctx->ldb, msg);
}
@ -949,7 +937,6 @@ int samdb_delete(void *ctx, TALLOC_CTX *mem_ctx, const char *dn)
{
struct ldb_wrap *sam_ctx = ctx;
ldb_set_alloc(sam_ctx->ldb, talloc_realloc_fn, mem_ctx);
return ldb_delete(sam_ctx->ldb, dn);
}
@ -960,7 +947,6 @@ int samdb_modify(void *ctx, TALLOC_CTX *mem_ctx, struct ldb_message *msg)
{
struct ldb_wrap *sam_ctx = ctx;
ldb_set_alloc(sam_ctx->ldb, talloc_realloc_fn, mem_ctx);
return ldb_modify(sam_ctx->ldb, msg);
}

View File

@ -309,7 +309,7 @@ static NTSTATUS rootdse_Search(struct ldapsrv_partition *partition, struct ldaps
void *local_ctx;
struct ldap_SearchResEntry *ent;
struct ldap_Result *done;
struct ldb_message **res;
struct ldb_message **res = NULL;
int result = LDAP_SUCCESS;
struct ldapsrv_reply *ent_r, *done_r;
struct rootdse_db_context *rootdsedb;
@ -338,8 +338,8 @@ static NTSTATUS rootdse_Search(struct ldapsrv_partition *partition, struct ldaps
attrs[j] = NULL;
}
ldb_set_alloc(rootdsedb->ldb, talloc_realloc_fn, rootdsedb);
count = ldb_search(rootdsedb->ldb, "", 0, "dn=cn=rootDSE", attrs, &res);
talloc_steal(rootdsedb, res);
if (count == 1) {
ent_r = ldapsrv_init_reply(call, LDAP_TAG_SearchResultEntry);

View File

@ -58,7 +58,7 @@ static NTSTATUS sldb_Search(struct ldapsrv_partition *partition, struct ldapsrv_
struct ldapsrv_reply *ent_r, *done_r;
int result = LDAP_SUCCESS;
struct samdb_context *samdb;
struct ldb_message **res;
struct ldb_message **res = NULL;
int i, j, y, count = 0;
enum ldb_scope scope = LDB_SCOPE_DEFAULT;
const char **attrs = NULL;
@ -102,8 +102,8 @@ static NTSTATUS sldb_Search(struct ldapsrv_partition *partition, struct ldapsrv_
attrs[i] = NULL;
}
ldb_set_alloc(samdb->ldb, talloc_realloc_fn, samdb);
count = ldb_search(samdb->ldb, basedn->dn, scope, r->filter, attrs, &res);
talloc_steal(samdb, res);
for (i=0; i < count; i++) {
ent_r = ldapsrv_init_reply(call, LDAP_TAG_SearchResultEntry);
@ -249,7 +249,6 @@ reply:
ALLOC_CHECK(add_reply);
if (result == LDAP_SUCCESS) {
ldb_set_alloc(samdb->ldb, talloc_realloc_fn, samdb);
ldb_ret = ldb_add(samdb->ldb, msg);
if (ldb_ret == 0) {
result = LDAP_SUCCESS;
@ -302,7 +301,6 @@ reply:
ALLOC_CHECK(del_reply);
if (result == LDAP_SUCCESS) {
ldb_set_alloc(samdb->ldb, talloc_realloc_fn, samdb);
ldb_ret = ldb_delete(samdb->ldb, dn->dn);
if (ldb_ret == 0) {
result = LDAP_SUCCESS;
@ -413,7 +411,6 @@ reply:
ALLOC_CHECK(modify_reply);
if (result == LDAP_SUCCESS) {
ldb_set_alloc(samdb->ldb, talloc_realloc_fn, samdb);
ldb_ret = ldb_modify(samdb->ldb, msg);
if (ldb_ret == 0) {
result = LDAP_SUCCESS;
@ -447,7 +444,7 @@ static NTSTATUS sldb_Compare(struct ldapsrv_partition *partition, struct ldapsrv
struct ldapsrv_reply *compare_r;
int result = LDAP_SUCCESS;
struct samdb_context *samdb;
struct ldb_message **res;
struct ldb_message **res = NULL;
const char *attrs[1];
const char *errstr = NULL;
const char *filter = NULL;
@ -475,8 +472,8 @@ reply:
ALLOC_CHECK(compare_r);
if (result == LDAP_SUCCESS) {
ldb_set_alloc(samdb->ldb, talloc_realloc_fn, samdb);
count = ldb_search(samdb->ldb, dn->dn, LDB_SCOPE_BASE, filter, attrs, &res);
talloc_steal(samdb, res);
if (count == 1) {
DEBUG(10,("sldb_Compare: matched\n"));
result = LDAP_COMPARE_TRUE;
@ -580,7 +577,6 @@ reply:
ALLOC_CHECK(modifydn_r);
if (result == LDAP_SUCCESS) {
ldb_set_alloc(samdb->ldb, talloc_realloc_fn, samdb);
ldb_ret = ldb_rename(samdb->ldb, olddn->dn, newdn);
if (ldb_ret == 0) {
result = LDAP_SUCCESS;

View File

@ -92,6 +92,7 @@ struct ldb_wrap *ldb_wrap_connect(TALLOC_CTX *mem_ctx,
talloc_free(w);
return NULL;
}
talloc_steal(w, w->ldb);
talloc_set_destructor(w, ldb_wrap_destructor);
ldb_set_debug(w->ldb, ldb_wrap_debug, NULL);

View File

@ -261,17 +261,17 @@ static WERROR ldb_open_hive(struct registry_hive *hive, struct registry_key **k)
static WERROR ldb_add_key (TALLOC_CTX *mem_ctx, struct registry_key *parent, const char *name, uint32_t access_mask, struct security_descriptor *sd, struct registry_key **newkey)
{
struct ldb_context *ctx = parent->hive->backend_data;
struct ldb_message msg;
struct ldb_message *msg;
struct ldb_key_data *newkd;
int ret;
ZERO_STRUCT(msg);
msg = ldb_msg_new(mem_ctx);
msg.dn = reg_path_to_ldb(mem_ctx, parent, name, NULL);
msg->dn = reg_path_to_ldb(msg, parent, name, NULL);
ldb_msg_add_string(ctx, &msg, "key", talloc_strdup(mem_ctx, name));
ldb_msg_add_string(ctx, msg, "key", talloc_strdup(mem_ctx, name));
ret = ldb_add(ctx, &msg);
ret = ldb_add(ctx, msg);
if (ret < 0) {
DEBUG(1, ("ldb_msg_add: %s\n", ldb_errstring(parent->hive->backend_data)));
return WERR_FOOBAR;
@ -281,7 +281,7 @@ static WERROR ldb_add_key (TALLOC_CTX *mem_ctx, struct registry_key *parent, con
(*newkey)->name = talloc_strdup(mem_ctx, name);
(*newkey)->backend_data = newkd = talloc_zero_p(*newkey, struct ldb_key_data);
newkd->dn = msg.dn;
newkd->dn = talloc_steal(newkd, msg->dn);
return WERR_OK;
}

View File

@ -43,10 +43,12 @@ int gendb_search_v(struct ldb_context *ldb,
return -1;
}
ldb_set_alloc(ldb, talloc_realloc_fn, mem_ctx);
*res = NULL;
count = ldb_search(ldb, basedn, LDB_SCOPE_SUBTREE, expr, attrs, res);
if (*res) talloc_steal(mem_ctx, *res);
DEBUG(4,("gendb_search_v: %s %s -> %d (%s)\n",
basedn?basedn:"NULL", expr, count,
count==-1?ldb_errstring(ldb):"OK"));

View File

@ -47,8 +47,6 @@ static struct ldb_wrap *schannel_db_connect(TALLOC_CTX *mem_ctx)
return NULL;
}
ldb_set_alloc(ldb->ldb, talloc_realloc_fn, mem_ctx);
return ldb;
}
@ -61,7 +59,7 @@ NTSTATUS schannel_store_session_key(TALLOC_CTX *mem_ctx,
struct creds_CredentialState *creds)
{
struct ldb_wrap *ldb;
struct ldb_message msg;
struct ldb_message *msg;
struct ldb_val val, seed;
char *s = NULL;
time_t expiry = time(NULL) + SCHANNEL_CREDENTIALS_EXPIRY;
@ -79,37 +77,44 @@ NTSTATUS schannel_store_session_key(TALLOC_CTX *mem_ctx,
return NT_STATUS_NO_MEMORY;
}
ZERO_STRUCT(msg);
msg.dn = talloc_strdup(mem_ctx, computer_name);
if (msg.dn == NULL) {
msg = ldb_msg_new(mem_ctx);
if (msg == NULL) {
talloc_free(ldb);
return NT_STATUS_NO_MEMORY;
}
msg->dn = talloc_strdup(msg, computer_name);
if (msg->dn == NULL) {
talloc_free(ldb);
talloc_free(msg);
return NT_STATUS_NO_MEMORY;
}
val.data = creds->session_key;
val.length = sizeof(creds->session_key);
seed.data = creds->seed.data;
seed.length = sizeof(creds->seed.data);
ldb_msg_add_value(ldb->ldb, &msg, "sessionKey", &val);
ldb_msg_add_value(ldb->ldb, &msg, "seed", &seed);
ldb_msg_add_string(ldb->ldb, &msg, "expiry", s);
ldb_msg_add_value(ldb->ldb, msg, "sessionKey", &val);
ldb_msg_add_value(ldb->ldb, msg, "seed", &seed);
ldb_msg_add_string(ldb->ldb, msg, "expiry", s);
ldb_delete(ldb->ldb, msg.dn);
ldb_delete(ldb->ldb, msg->dn);
ret = ldb_add(ldb->ldb, &msg);
ret = ldb_add(ldb->ldb, msg);
talloc_free(s);
if (ret != 0) {
DEBUG(0,("Unable to add %s to session key db - %s\n",
msg.dn, ldb_errstring(ldb->ldb)));
msg->dn, ldb_errstring(ldb->ldb)));
talloc_free(ldb);
talloc_free(msg);
return NT_STATUS_INTERNAL_DB_CORRUPTION;
}
talloc_free(msg);
talloc_free(ldb);
return NT_STATUS_OK;

View File

@ -478,7 +478,7 @@ static NTSTATUS samr_CreateDomainGroup(struct dcesrv_call_state *dce_call, TALLO
struct samr_account_state *a_state;
struct dcesrv_handle *h;
const char *name;
struct ldb_message msg;
struct ldb_message *msg;
uint32_t rid;
const char *groupname, *sidstr, *guidstr;
struct GUID guid;
@ -509,10 +509,13 @@ static NTSTATUS samr_CreateDomainGroup(struct dcesrv_call_state *dce_call, TALLO
return NT_STATUS_GROUP_EXISTS;
}
ZERO_STRUCT(msg);
msg = ldb_msg_new(mem_ctx);
if (msg == NULL) {
return NT_STATUS_NO_MEMORY;
}
/* pull in all the template attributes */
ret = samdb_copy_template(d_state->sam_ctx, mem_ctx, &msg,
ret = samdb_copy_template(d_state->sam_ctx, mem_ctx, msg,
"(&(name=TemplateGroup)(objectclass=groupTemplate))");
if (ret != 0) {
DEBUG(0,("Failed to load TemplateGroup from samdb\n"));
@ -540,24 +543,24 @@ static NTSTATUS samr_CreateDomainGroup(struct dcesrv_call_state *dce_call, TALLO
}
/* add core elements to the ldb_message for the user */
msg.dn = talloc_asprintf(mem_ctx, "CN=%s,CN=Users,%s", groupname,
d_state->domain_dn);
if (!msg.dn) {
msg->dn = talloc_asprintf(mem_ctx, "CN=%s,CN=Users,%s", groupname,
d_state->domain_dn);
if (!msg->dn) {
return NT_STATUS_NO_MEMORY;
}
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, &msg, "name", groupname);
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, &msg, "cn", groupname);
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, &msg, "sAMAccountName", groupname);
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, &msg, "objectClass", "group");
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, &msg, "objectSid", sidstr);
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, &msg, "objectGUID", guidstr);
samdb_msg_set_ldaptime(d_state->sam_ctx, mem_ctx, &msg, "whenCreated", now);
samdb_msg_set_ldaptime(d_state->sam_ctx, mem_ctx, &msg, "whenChanged", now);
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, msg, "name", groupname);
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, msg, "cn", groupname);
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, msg, "sAMAccountName", groupname);
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, msg, "objectClass", "group");
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, msg, "objectSid", sidstr);
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, msg, "objectGUID", guidstr);
samdb_msg_set_ldaptime(d_state->sam_ctx, mem_ctx, msg, "whenCreated", now);
samdb_msg_set_ldaptime(d_state->sam_ctx, mem_ctx, msg, "whenChanged", now);
/* create the group */
ret = samdb_add(d_state->sam_ctx, mem_ctx, &msg);
ret = samdb_add(d_state->sam_ctx, mem_ctx, msg);
if (ret != 0) {
DEBUG(0,("Failed to create group record %s\n", msg.dn));
DEBUG(0,("Failed to create group record %s\n", msg->dn));
return NT_STATUS_INTERNAL_DB_CORRUPTION;
}
@ -568,7 +571,7 @@ static NTSTATUS samr_CreateDomainGroup(struct dcesrv_call_state *dce_call, TALLO
a_state->sam_ctx = d_state->sam_ctx;
a_state->access_mask = r->in.access_mask;
a_state->domain_state = talloc_reference(a_state, d_state);
a_state->account_dn = talloc_steal(a_state, msg.dn);
a_state->account_dn = talloc_steal(a_state, msg->dn);
a_state->account_sid = talloc_steal(a_state, sidstr);
a_state->account_name = talloc_strdup(a_state, groupname);
if (!a_state->account_name) {
@ -711,7 +714,7 @@ static NTSTATUS samr_CreateUser2(struct dcesrv_call_state *dce_call, TALLOC_CTX
struct samr_account_state *a_state;
struct dcesrv_handle *h;
const char *name;
struct ldb_message msg;
struct ldb_message *msg;
uint32_t rid;
const char *account_name, *sidstr, *guidstr;
struct GUID guid;
@ -743,12 +746,15 @@ static NTSTATUS samr_CreateUser2(struct dcesrv_call_state *dce_call, TALLOC_CTX
return NT_STATUS_USER_EXISTS;
}
ZERO_STRUCT(msg);
msg = ldb_msg_new(mem_ctx);
if (msg == NULL) {
return NT_STATUS_NO_MEMORY;
}
/* This must be one of these values *only* */
if (r->in.acct_flags == ACB_NORMAL) {
/* pull in all the template attributes */
ret = samdb_copy_template(d_state->sam_ctx, mem_ctx, &msg,
ret = samdb_copy_template(d_state->sam_ctx, mem_ctx, msg,
"(&(name=TemplateUser)(objectclass=userTemplate))");
if (ret != 0) {
DEBUG(0,("Failed to load TemplateUser from samdb\n"));
@ -759,7 +765,7 @@ static NTSTATUS samr_CreateUser2(struct dcesrv_call_state *dce_call, TALLOC_CTX
} else if (r->in.acct_flags == ACB_WSTRUST) {
/* pull in all the template attributes */
ret = samdb_copy_template(d_state->sam_ctx, mem_ctx, &msg,
ret = samdb_copy_template(d_state->sam_ctx, mem_ctx, msg,
"(&(name=TemplateMemberServer)(objectclass=userTemplate))");
if (ret != 0) {
DEBUG(0,("Failed to load TemplateMemberServer from samdb\n"));
@ -771,7 +777,7 @@ static NTSTATUS samr_CreateUser2(struct dcesrv_call_state *dce_call, TALLOC_CTX
} else if (r->in.acct_flags == ACB_SVRTRUST) {
/* pull in all the template attributes */
ret = samdb_copy_template(d_state->sam_ctx, mem_ctx, &msg,
ret = samdb_copy_template(d_state->sam_ctx, mem_ctx, msg,
"(&(name=TemplateDomainController)(objectclass=userTemplate))");
if (ret != 0) {
DEBUG(0,("Failed to load TemplateDomainController from samdb\n"));
@ -783,7 +789,7 @@ static NTSTATUS samr_CreateUser2(struct dcesrv_call_state *dce_call, TALLOC_CTX
} else if (r->in.acct_flags == ACB_DOMTRUST) {
/* pull in all the template attributes */
ret = samdb_copy_template(d_state->sam_ctx, mem_ctx, &msg,
ret = samdb_copy_template(d_state->sam_ctx, mem_ctx, msg,
"(&(name=TemplateTrustingDomain)(objectclass=userTemplate))");
if (ret != 0) {
DEBUG(0,("Failed to load TemplateTrustingDomain from samdb\n"));
@ -818,26 +824,26 @@ static NTSTATUS samr_CreateUser2(struct dcesrv_call_state *dce_call, TALLOC_CTX
}
/* add core elements to the ldb_message for the user */
msg.dn = talloc_asprintf(mem_ctx, "CN=%s,CN=%s,%s", account_name, container, d_state->domain_dn);
if (!msg.dn) {
msg->dn = talloc_asprintf(mem_ctx, "CN=%s,CN=%s,%s", account_name, container, d_state->domain_dn);
if (!msg->dn) {
return NT_STATUS_NO_MEMORY;
}
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, &msg, "name", account_name);
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, &msg, "cn", account_name);
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, &msg, "sAMAccountName", account_name);
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, &msg, "objectClass", "user");
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, msg, "name", account_name);
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, msg, "cn", account_name);
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, msg, "sAMAccountName", account_name);
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, msg, "objectClass", "user");
if (additional_class) {
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, &msg, "objectClass", additional_class);
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, msg, "objectClass", additional_class);
}
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, &msg, "objectSid", sidstr);
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, &msg, "objectGUID", guidstr);
samdb_msg_set_ldaptime(d_state->sam_ctx, mem_ctx, &msg, "whenCreated", now);
samdb_msg_set_ldaptime(d_state->sam_ctx, mem_ctx, &msg, "whenChanged", now);
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, msg, "objectSid", sidstr);
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, msg, "objectGUID", guidstr);
samdb_msg_set_ldaptime(d_state->sam_ctx, mem_ctx, msg, "whenCreated", now);
samdb_msg_set_ldaptime(d_state->sam_ctx, mem_ctx, msg, "whenChanged", now);
/* create the user */
ret = samdb_add(d_state->sam_ctx, mem_ctx, &msg);
ret = samdb_add(d_state->sam_ctx, mem_ctx, msg);
if (ret != 0) {
DEBUG(0,("Failed to create user record %s\n", msg.dn));
DEBUG(0,("Failed to create user record %s\n", msg->dn));
return NT_STATUS_INTERNAL_DB_CORRUPTION;
}
@ -848,7 +854,7 @@ static NTSTATUS samr_CreateUser2(struct dcesrv_call_state *dce_call, TALLOC_CTX
a_state->sam_ctx = d_state->sam_ctx;
a_state->access_mask = r->in.access_mask;
a_state->domain_state = talloc_reference(a_state, d_state);
a_state->account_dn = talloc_steal(a_state, msg.dn);
a_state->account_dn = talloc_steal(a_state, msg->dn);
a_state->account_sid = talloc_steal(a_state, sidstr);
a_state->account_name = talloc_strdup(a_state, account_name);
if (!a_state->account_name) {
@ -987,7 +993,7 @@ static NTSTATUS samr_CreateDomAlias(struct dcesrv_call_state *dce_call, TALLOC_C
const char *aliasname, *name, *sidstr, *guidstr;
struct GUID guid;
time_t now = time(NULL);
struct ldb_message msg;
struct ldb_message *msg;
uint32_t rid;
struct dcesrv_handle *a_handle;
int ret;
@ -1016,10 +1022,13 @@ static NTSTATUS samr_CreateDomAlias(struct dcesrv_call_state *dce_call, TALLOC_C
return NT_STATUS_ALIAS_EXISTS;
}
ZERO_STRUCT(msg);
msg = ldb_msg_new(mem_ctx);
if (msg == NULL) {
return NT_STATUS_NO_MEMORY;
}
/* pull in all the template attributes */
ret = samdb_copy_template(d_state->sam_ctx, mem_ctx, &msg,
ret = samdb_copy_template(d_state->sam_ctx, mem_ctx, msg,
"(&(name=TemplateAlias)"
"(objectclass=aliasTemplate))");
if (ret != 0) {
@ -1048,25 +1057,25 @@ static NTSTATUS samr_CreateDomAlias(struct dcesrv_call_state *dce_call, TALLOC_C
}
/* add core elements to the ldb_message for the alias */
msg.dn = talloc_asprintf(mem_ctx, "CN=%s,CN=Users,%s", aliasname,
msg->dn = talloc_asprintf(mem_ctx, "CN=%s,CN=Users,%s", aliasname,
d_state->domain_dn);
if (!msg.dn) {
if (!msg->dn) {
return NT_STATUS_NO_MEMORY;
}
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, &msg, "name", aliasname);
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, &msg, "cn", aliasname);
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, &msg, "sAMAccountName", aliasname);
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, &msg, "objectClass", "group");
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, &msg, "objectSid", sidstr);
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, &msg, "objectGUID", guidstr);
samdb_msg_set_ldaptime(d_state->sam_ctx, mem_ctx, &msg, "whenCreated", now);
samdb_msg_set_ldaptime(d_state->sam_ctx, mem_ctx, &msg, "whenChanged", now);
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, msg, "name", aliasname);
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, msg, "cn", aliasname);
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, msg, "sAMAccountName", aliasname);
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, msg, "objectClass", "group");
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, msg, "objectSid", sidstr);
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, msg, "objectGUID", guidstr);
samdb_msg_set_ldaptime(d_state->sam_ctx, mem_ctx, msg, "whenCreated", now);
samdb_msg_set_ldaptime(d_state->sam_ctx, mem_ctx, msg, "whenChanged", now);
/* create the alias */
ret = samdb_add(d_state->sam_ctx, mem_ctx, &msg);
ret = samdb_add(d_state->sam_ctx, mem_ctx, msg);
if (ret != 0) {
DEBUG(0,("Failed to create alias record %s\n", msg.dn));
DEBUG(0,("Failed to create alias record %s\n", msg->dn));
return NT_STATUS_INTERNAL_DB_CORRUPTION;
}
@ -1078,7 +1087,7 @@ static NTSTATUS samr_CreateDomAlias(struct dcesrv_call_state *dce_call, TALLOC_C
a_state->sam_ctx = d_state->sam_ctx;
a_state->access_mask = r->in.access_mask;
a_state->domain_state = talloc_reference(a_state, d_state);
a_state->account_dn = talloc_steal(a_state, msg.dn);
a_state->account_dn = talloc_steal(a_state, msg->dn);
a_state->account_sid = talloc_steal(a_state, sidstr);
a_state->account_name = talloc_strdup(a_state, aliasname);
if (!a_state->account_name) {
@ -1635,20 +1644,24 @@ static NTSTATUS samr_QueryGroupInfo(struct dcesrv_call_state *dce_call, TALLOC_C
samr_SetGroupInfo
*/
static NTSTATUS samr_SetGroupInfo(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
struct samr_SetGroupInfo *r)
struct samr_SetGroupInfo *r)
{
struct dcesrv_handle *h;
struct samr_account_state *a_state;
struct ldb_message mod, *msg = &mod;
struct ldb_message *msg;
int ret;
DCESRV_PULL_HANDLE(h, r->in.group_handle, SAMR_HANDLE_GROUP);
a_state = h->data;
ZERO_STRUCT(mod);
mod.dn = talloc_strdup(mem_ctx, a_state->account_dn);
if (!mod.dn) {
msg = ldb_msg_new(mem_ctx);
if (msg == NULL) {
return NT_STATUS_NO_MEMORY;
}
msg->dn = talloc_strdup(mem_ctx, a_state->account_dn);
if (!msg->dn) {
return NT_STATUS_NO_MEMORY;
}
@ -1669,7 +1682,7 @@ static NTSTATUS samr_SetGroupInfo(struct dcesrv_call_state *dce_call, TALLOC_CTX
}
/* modify the samdb record */
ret = samdb_replace(a_state->sam_ctx, mem_ctx, &mod);
ret = samdb_replace(a_state->sam_ctx, mem_ctx, msg);
if (ret != 0) {
/* we really need samdb.c to return NTSTATUS */
return NT_STATUS_UNSUCCESSFUL;
@ -1688,7 +1701,7 @@ static NTSTATUS samr_AddGroupMember(struct dcesrv_call_state *dce_call, TALLOC_C
struct dcesrv_handle *h;
struct samr_account_state *a_state;
struct samr_domain_state *d_state;
struct ldb_message mod;
struct ldb_message *mod;
char *membersidstr;
const char *memberdn;
struct ldb_message **msgs;
@ -1722,14 +1735,18 @@ static NTSTATUS samr_AddGroupMember(struct dcesrv_call_state *dce_call, TALLOC_C
if (memberdn == NULL)
return NT_STATUS_INTERNAL_DB_CORRUPTION;
ZERO_STRUCT(mod);
mod.dn = talloc_reference(mem_ctx, a_state->account_dn);
mod = ldb_msg_new(mem_ctx);
if (mod == NULL) {
return NT_STATUS_NO_MEMORY;
}
if (samdb_msg_add_addval(d_state->sam_ctx, mem_ctx, &mod, "member",
mod->dn = talloc_reference(mem_ctx, a_state->account_dn);
if (samdb_msg_add_addval(d_state->sam_ctx, mem_ctx, mod, "member",
memberdn) != 0)
return NT_STATUS_UNSUCCESSFUL;
if (samdb_modify(a_state->sam_ctx, mem_ctx, &mod) != 0)
if (samdb_modify(a_state->sam_ctx, mem_ctx, mod) != 0)
return NT_STATUS_UNSUCCESSFUL;
return NT_STATUS_OK;
@ -1772,7 +1789,7 @@ static NTSTATUS samr_DeleteGroupMember(struct dcesrv_call_state *dce_call, TALLO
struct dcesrv_handle *h;
struct samr_account_state *a_state;
struct samr_domain_state *d_state;
struct ldb_message mod;
struct ldb_message *mod;
char *membersidstr;
const char *memberdn;
struct ldb_message **msgs;
@ -1806,14 +1823,18 @@ static NTSTATUS samr_DeleteGroupMember(struct dcesrv_call_state *dce_call, TALLO
if (memberdn == NULL)
return NT_STATUS_INTERNAL_DB_CORRUPTION;
ZERO_STRUCT(mod);
mod.dn = talloc_reference(mem_ctx, a_state->account_dn);
mod = ldb_msg_new(mem_ctx);
if (mod == NULL) {
return NT_STATUS_NO_MEMORY;
}
if (samdb_msg_add_delval(d_state->sam_ctx, mem_ctx, &mod, "member",
mod->dn = talloc_reference(mem_ctx, a_state->account_dn);
if (samdb_msg_add_delval(d_state->sam_ctx, mem_ctx, mod, "member",
memberdn) != 0)
return NT_STATUS_UNSUCCESSFUL;
if (samdb_modify(a_state->sam_ctx, mem_ctx, &mod) != 0)
if (samdb_modify(a_state->sam_ctx, mem_ctx, mod) != 0)
return NT_STATUS_UNSUCCESSFUL;
return NT_STATUS_OK;
@ -2049,16 +2070,20 @@ static NTSTATUS samr_SetAliasInfo(struct dcesrv_call_state *dce_call, TALLOC_CTX
{
struct dcesrv_handle *h;
struct samr_account_state *a_state;
struct ldb_message mod, *msg = &mod;
struct ldb_message *msg;
int ret;
DCESRV_PULL_HANDLE(h, r->in.alias_handle, SAMR_HANDLE_ALIAS);
a_state = h->data;
ZERO_STRUCT(mod);
mod.dn = talloc_strdup(mem_ctx, a_state->account_dn);
if (!mod.dn) {
msg = ldb_msg_new(mem_ctx);
if (msg == NULL) {
return NT_STATUS_NO_MEMORY;
}
msg->dn = talloc_strdup(mem_ctx, a_state->account_dn);
if (!msg->dn) {
return NT_STATUS_NO_MEMORY;
}
@ -2076,7 +2101,7 @@ static NTSTATUS samr_SetAliasInfo(struct dcesrv_call_state *dce_call, TALLOC_CTX
}
/* modify the samdb record */
ret = samdb_replace(a_state->sam_ctx, mem_ctx, &mod);
ret = samdb_replace(a_state->sam_ctx, mem_ctx, msg);
if (ret != 0) {
/* we really need samdb.c to return NTSTATUS */
return NT_STATUS_UNSUCCESSFUL;
@ -2106,7 +2131,7 @@ static NTSTATUS samr_AddAliasMember(struct dcesrv_call_state *dce_call, TALLOC_C
struct samr_account_state *a_state;
struct samr_domain_state *d_state;
const char *sidstr;
struct ldb_message mod;
struct ldb_message *mod;
struct ldb_message **msgs;
const char * const attrs[2] = { "dn", NULL };
const char *memberdn = NULL;
@ -2130,7 +2155,7 @@ static NTSTATUS samr_AddAliasMember(struct dcesrv_call_state *dce_call, TALLOC_C
DEBUG(0,("Found %d records matching sid %s\n", ret, sidstr));
return NT_STATUS_INTERNAL_DB_CORRUPTION;
} else if (ret == 0) {
struct ldb_message msg;
struct ldb_message *msg;
struct GUID guid;
const char *guidstr, *basedn;
@ -2141,10 +2166,13 @@ static NTSTATUS samr_AddAliasMember(struct dcesrv_call_state *dce_call, TALLOC_C
r->in.sid))
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
ZERO_STRUCT(msg);
msg = ldb_msg_new(mem_ctx);
if (msg == NULL) {
return NT_STATUS_NO_MEMORY;
}
/* pull in all the template attributes */
ret = samdb_copy_template(d_state->sam_ctx, mem_ctx, &msg,
ret = samdb_copy_template(d_state->sam_ctx, mem_ctx, msg,
"(&(name=TemplateForeignSecurityPrincipal)"
"(objectclass=foreignSecurityPrincipalTemplate))");
if (ret != 0) {
@ -2179,27 +2207,27 @@ static NTSTATUS samr_AddAliasMember(struct dcesrv_call_state *dce_call, TALLOC_C
}
/* add core elements to the ldb_message for the alias */
msg.dn = talloc_asprintf(mem_ctx, "CN=%s,%s", sidstr, basedn);
if (msg.dn == NULL)
msg->dn = talloc_asprintf(mem_ctx, "CN=%s,%s", sidstr, basedn);
if (msg->dn == NULL)
return NT_STATUS_NO_MEMORY;
memberdn = msg.dn;
memberdn = msg->dn;
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, &msg,
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, msg,
"name", sidstr);
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, &msg,
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, msg,
"objectClass",
"foreignSecurityPrincipal");
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, &msg,
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, msg,
"objectSid", sidstr);
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, &msg,
samdb_msg_add_string(d_state->sam_ctx, mem_ctx, msg,
"objectGUID", guidstr);
/* create the alias */
ret = samdb_add(d_state->sam_ctx, mem_ctx, &msg);
ret = samdb_add(d_state->sam_ctx, mem_ctx, msg);
if (ret != 0) {
DEBUG(0,("Failed to create foreignSecurityPrincipal "
"record %s\n", msg.dn));
"record %s\n", msg->dn));
return NT_STATUS_INTERNAL_DB_CORRUPTION;
}
} else {
@ -2211,14 +2239,18 @@ static NTSTATUS samr_AddAliasMember(struct dcesrv_call_state *dce_call, TALLOC_C
return NT_STATUS_INTERNAL_DB_CORRUPTION;
}
ZERO_STRUCT(mod);
mod.dn = talloc_reference(mem_ctx, a_state->account_dn);
mod = ldb_msg_new(mem_ctx);
if (mod == NULL) {
return NT_STATUS_NO_MEMORY;
}
if (samdb_msg_add_addval(d_state->sam_ctx, mem_ctx, &mod, "member",
mod->dn = talloc_reference(mem_ctx, a_state->account_dn);
if (samdb_msg_add_addval(d_state->sam_ctx, mem_ctx, mod, "member",
memberdn) != 0)
return NT_STATUS_UNSUCCESSFUL;
if (samdb_modify(a_state->sam_ctx, mem_ctx, &mod) != 0)
if (samdb_modify(a_state->sam_ctx, mem_ctx, mod) != 0)
return NT_STATUS_UNSUCCESSFUL;
return NT_STATUS_OK;
@ -2235,7 +2267,7 @@ static NTSTATUS samr_DeleteAliasMember(struct dcesrv_call_state *dce_call, TALLO
struct samr_account_state *a_state;
struct samr_domain_state *d_state;
const char *sidstr;
struct ldb_message mod;
struct ldb_message *mod;
const char *memberdn;
DCESRV_PULL_HANDLE(h, r->in.alias_handle, SAMR_HANDLE_ALIAS);
@ -2253,14 +2285,18 @@ static NTSTATUS samr_DeleteAliasMember(struct dcesrv_call_state *dce_call, TALLO
if (memberdn == NULL)
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
ZERO_STRUCT(mod);
mod.dn = talloc_reference(mem_ctx, a_state->account_dn);
mod = ldb_msg_new(mem_ctx);
if (mod == NULL) {
return NT_STATUS_NO_MEMORY;
}
if (samdb_msg_add_delval(d_state->sam_ctx, mem_ctx, &mod, "member",
mod->dn = talloc_reference(mem_ctx, a_state->account_dn);
if (samdb_msg_add_delval(d_state->sam_ctx, mem_ctx, mod, "member",
memberdn) != 0)
return NT_STATUS_UNSUCCESSFUL;
if (samdb_modify(a_state->sam_ctx, mem_ctx, &mod) != 0)
if (samdb_modify(a_state->sam_ctx, mem_ctx, mod) != 0)
return NT_STATUS_UNSUCCESSFUL;
return NT_STATUS_OK;
@ -2621,7 +2657,7 @@ static NTSTATUS samr_SetUserInfo(struct dcesrv_call_state *dce_call, TALLOC_CTX
{
struct dcesrv_handle *h;
struct samr_account_state *a_state;
struct ldb_message mod, *msg = &mod;
struct ldb_message *msg;
int ret;
NTSTATUS status = NT_STATUS_OK;
@ -2629,9 +2665,13 @@ static NTSTATUS samr_SetUserInfo(struct dcesrv_call_state *dce_call, TALLOC_CTX
a_state = h->data;
ZERO_STRUCT(mod);
mod.dn = talloc_strdup(mem_ctx, a_state->account_dn);
if (!mod.dn) {
msg = ldb_msg_new(mem_ctx);
if (msg == NULL) {
return NT_STATUS_NO_MEMORY;
}
msg->dn = talloc_strdup(mem_ctx, a_state->account_dn);
if (!msg->dn) {
return NT_STATUS_NO_MEMORY;
}
@ -3216,21 +3256,29 @@ static NTSTATUS samr_RemoveMemberFromForeignDomain(struct dcesrv_call_state *dce
return NT_STATUS_INTERNAL_DB_CORRUPTION;
for (i=0; i<count; i++) {
struct ldb_message mod;
ZERO_STRUCT(mod);
struct ldb_message *mod;
mod.dn = talloc_reference(mem_ctx,
samdb_result_string(res[i], "dn",
NULL));
if (mod.dn == NULL)
mod = ldb_msg_new(mem_ctx);
if (mod == NULL) {
return NT_STATUS_NO_MEMORY;
}
mod->dn = talloc_reference(mod,
samdb_result_string(res[i], "dn",
NULL));
if (mod->dn == NULL) {
talloc_free(mod);
continue;
}
if (samdb_msg_add_delval(d_state->sam_ctx, mem_ctx, &mod,
if (samdb_msg_add_delval(d_state->sam_ctx, mem_ctx, mod,
"member", memberdn) != 0)
return NT_STATUS_NO_MEMORY;
if (samdb_modify(d_state->sam_ctx, mem_ctx, &mod) != 0)
if (samdb_modify(d_state->sam_ctx, mem_ctx, mod) != 0)
return NT_STATUS_UNSUCCESSFUL;
talloc_free(mod);
}
return NT_STATUS_OK;

View File

@ -2199,6 +2199,8 @@ double torture_create_procs(BOOL (*fn)(struct smbcli_state *, int), BOOL *result
int num_unc_names = 0;
struct timeval tv;
*result = True;
synccount = 0;
signal(SIGCONT, sigcont);
@ -2492,7 +2494,7 @@ static BOOL run_test(const char *name)
init_iconv();
printf("Running %s\n", torture_ops[i].name);
if (torture_ops[i].multi_fn) {
BOOL result;
BOOL result = False;
t = torture_create_procs(torture_ops[i].multi_fn,
&result);
if (!result) {