summaryrefslogtreecommitdiff
path: root/source4/rpc_server/samr
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-05-06 07:32:51 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:51:46 -0500
commit51803f76c8a05d9ce7b26215bc9ada9216fe6d59 (patch)
tree65f2836660a30eaa2f0be03d9aba2175ef39b615 /source4/rpc_server/samr
parent7216d23ba5eef36872196eaeb0b629fe0cf272c5 (diff)
downloadsamba-51803f76c8a05d9ce7b26215bc9ada9216fe6d59.tar.gz
samba-51803f76c8a05d9ce7b26215bc9ada9216fe6d59.tar.bz2
samba-51803f76c8a05d9ce7b26215bc9ada9216fe6d59.zip
r510: converted the samdb code to give ldb a talloc context rather than letting ldb use malloc
(This used to be commit a3edd4bca8769cd804a5908286c7a18ca5c8fa00)
Diffstat (limited to 'source4/rpc_server/samr')
-rw-r--r--source4/rpc_server/samr/dcesrv_samr.c73
-rw-r--r--source4/rpc_server/samr/samdb.c50
2 files changed, 86 insertions, 37 deletions
diff --git a/source4/rpc_server/samr/dcesrv_samr.c b/source4/rpc_server/samr/dcesrv_samr.c
index 2fb061830d..af716e5cef 100644
--- a/source4/rpc_server/samr/dcesrv_samr.c
+++ b/source4/rpc_server/samr/dcesrv_samr.c
@@ -53,6 +53,16 @@ struct samr_domain_state {
const char *domain_name;
};
+/*
+ state associated with a open user handle
+*/
+struct samr_user_state {
+ TALLOC_CTX *mem_ctx;
+ uint32 access_mask;
+ const char *user_sid;
+ const char *user_name;
+};
+
/*
destroy an open connection. This closes the database connection
@@ -286,7 +296,7 @@ static NTSTATUS samr_OpenDomain(struct dcesrv_call_state *dce_call, TALLOC_CTX *
struct samr_OpenDomain *r)
{
struct dcesrv_handle *h_conn, *h_domain;
- const char *sidstr, *domain_name;
+ char *sidstr, *domain_name;
struct samr_domain_state *state;
TALLOC_CTX *mem_ctx2;
@@ -369,19 +379,56 @@ static NTSTATUS samr_CreateDomainGroup(struct dcesrv_call_state *dce_call, TALLO
samr_EnumDomainGroups
*/
static NTSTATUS samr_EnumDomainGroups(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
- struct samr_EnumDomainGroups *r)
+ struct samr_EnumDomainGroups *r)
{
DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
}
/*
+ samr_CreateUser2
+*/
+static NTSTATUS samr_CreateUser2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
+ struct samr_CreateUser2 *r)
+{
+ struct samr_user_state *state;
+ struct dcesrv_handle *h = dcesrv_handle_fetch(dce_call->conn,
+ r->in.handle,
+ SAMR_HANDLE_DOMAIN);
+ DCESRV_CHECK_HANDLE(h);
+
+ /* check if the user already exists */
+ /* read the default user template */
+ /* allocate a rid */
+ /* create a ldb_message for the user */
+ /* create the user */
+ /* create user state and new policy handle */
+
+
+ DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
+}
+
+
+/*
samr_CreateUser
*/
static NTSTATUS samr_CreateUser(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
- struct samr_CreateUser *r)
+ struct samr_CreateUser *r)
{
- DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
+ struct samr_CreateUser2 r2;
+ uint32 access_granted, rid;
+
+
+ /* a simple wrapper around samr_CreateUser2 works nicely */
+ r2.in.handle = r->in.handle;
+ r2.in.username = r->in.username;
+ r2.in.acct_flags = 1234;
+ r2.in.access_mask = r->in.access_mask;
+ r2.out.acct_handle = r->out.acct_handle;
+ r2.out.access_granted = &access_granted;
+ r2.out.rid = &rid;
+
+ return samr_CreateUser2(dce_call, mem_ctx, &r2);
}
@@ -756,16 +803,6 @@ static NTSTATUS samr_GetDisplayEnumerationIndex2(struct dcesrv_call_state *dce_c
/*
- samr_CreateUser2
-*/
-static NTSTATUS samr_CreateUser2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
- struct samr_CreateUser2 *r)
-{
- DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
-}
-
-
-/*
samr_QueryDisplayInfo3
*/
static NTSTATUS samr_QueryDisplayInfo3(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
@@ -825,27 +862,27 @@ static NTSTATUS samr_GetDomPwInfo(struct dcesrv_call_state *dce_call, TALLOC_CTX
{
struct ldb_message **msgs;
int ret;
- const char * const attrs[] = {"minPwdLength", "pwdProperties", NULL };
+ char * const attrs[] = {"minPwdLength", "pwdProperties", NULL };
if (r->in.name == NULL || r->in.name->name == NULL) {
return NT_STATUS_NO_SUCH_DOMAIN;
}
- ret = samdb_search(&msgs, attrs,
+ ret = samdb_search(mem_ctx, &msgs, attrs,
"(&(name=%s)(objectclass=domain))",
r->in.name->name);
if (ret <= 0) {
return NT_STATUS_NO_SUCH_DOMAIN;
}
if (ret > 1) {
- samdb_search_free(msgs);
+ samdb_search_free(mem_ctx, msgs);
return NT_STATUS_INTERNAL_DB_CORRUPTION;
}
r->out.info.min_pwd_len = samdb_result_uint(msgs[0], "minPwdLength", 0);
r->out.info.password_properties = samdb_result_uint(msgs[0], "pwdProperties", 1);
- samdb_search_free(msgs);
+ samdb_search_free(mem_ctx, msgs);
return NT_STATUS_OK;
}
diff --git a/source4/rpc_server/samr/samdb.c b/source4/rpc_server/samr/samdb.c
index 3f55698376..c4909caeb0 100644
--- a/source4/rpc_server/samr/samdb.c
+++ b/source4/rpc_server/samr/samdb.c
@@ -50,12 +50,20 @@ int samdb_connect(void)
return 0;
}
+/*
+ a alloc function for ldb
+*/
+static void *samdb_alloc(void *context, void *ptr, size_t size)
+{
+ return talloc_realloc((TALLOC_CTX *)context, ptr, size);
+}
/*
search the sam for the specified attributes - va_list varient
*/
-int samdb_search_v(struct ldb_message ***res,
- const char * const *attrs,
+int samdb_search_v(TALLOC_CTX *mem_ctx,
+ struct ldb_message ***res,
+ char * const *attrs,
const char *format,
va_list ap)
{
@@ -67,6 +75,8 @@ int samdb_search_v(struct ldb_message ***res,
return -1;
}
+ ldb_set_alloc(sam_db, samdb_alloc, mem_ctx);
+
count = ldb_search(sam_db, NULL, LDB_SCOPE_SUBTREE, expr, attrs, res);
free(expr);
@@ -78,15 +88,16 @@ int samdb_search_v(struct ldb_message ***res,
/*
search the sam for the specified attributes - varargs varient
*/
-int samdb_search(struct ldb_message ***res,
- const char * const *attrs,
+int samdb_search(TALLOC_CTX *mem_ctx,
+ struct ldb_message ***res,
+ char * const *attrs,
const char *format, ...)
{
va_list ap;
int count;
va_start(ap, format);
- count = samdb_search_v(res, attrs, format, ap);
+ count = samdb_search_v(mem_ctx, res, attrs, format, ap);
va_end(ap);
return count;
@@ -95,8 +106,9 @@ int samdb_search(struct ldb_message ***res,
/*
free up a search result
*/
-int samdb_search_free(struct ldb_message **res)
+int samdb_search_free(TALLOC_CTX *mem_ctx, struct ldb_message **res)
{
+ ldb_set_alloc(sam_db, samdb_alloc, mem_ctx);
return ldb_search_free(sam_db, res);
}
@@ -104,18 +116,18 @@ int samdb_search_free(struct ldb_message **res)
/*
search the sam for a single string attribute in exactly 1 record
*/
-const char *samdb_search_string(TALLOC_CTX *mem_ctx,
- const char *attr_name,
- const char *format, ...)
+char *samdb_search_string(TALLOC_CTX *mem_ctx,
+ const char *attr_name,
+ const char *format, ...)
{
va_list ap;
int count;
- const char * const attrs[2] = { attr_name, NULL };
+ char * const attrs[2] = { attr_name, NULL };
struct ldb_message **res = NULL;
- const char *str = NULL;
+ char *str = NULL;
va_start(ap, format);
- count = samdb_search_v(&res, attrs, format, ap);
+ count = samdb_search_v(mem_ctx, &res, attrs, format, ap);
va_end(ap);
if (count == 0) {
@@ -129,7 +141,7 @@ const char *samdb_search_string(TALLOC_CTX *mem_ctx,
res[0]->elements[0].values[0].data == NULL) {
DEBUG(1,("samdb: search for %s %s not single valued\n",
attr_name, format));
- samdb_search_free(res);
+ samdb_search_free(mem_ctx, res);
return NULL;
}
@@ -137,7 +149,7 @@ const char *samdb_search_string(TALLOC_CTX *mem_ctx,
res[0]->elements[0].values[0].data,
res[0]->elements[0].values[0].length);
- samdb_search_free(res);
+ samdb_search_free(mem_ctx, res);
return str;
}
@@ -154,11 +166,11 @@ int samdb_search_string_multiple(TALLOC_CTX *mem_ctx,
{
va_list ap;
int count, i;
- const char * const attrs[2] = { attr_name, NULL };
+ char * const attrs[2] = { attr_name, NULL };
struct ldb_message **res = NULL;
va_start(ap, format);
- count = samdb_search_v(&res, attrs, format, ap);
+ count = samdb_search_v(mem_ctx, &res, attrs, format, ap);
va_end(ap);
if (count <= 0) {
@@ -172,14 +184,14 @@ int samdb_search_string_multiple(TALLOC_CTX *mem_ctx,
res[i]->elements[0].values[0].data == NULL) {
DEBUG(1,("samdb: search for %s %s not single valued\n",
attr_name, format));
- samdb_search_free(res);
+ samdb_search_free(mem_ctx, res);
return -1;
}
}
*strs = talloc_array_p(mem_ctx, char *, count+1);
if (! *strs) {
- samdb_search_free(res);
+ samdb_search_free(mem_ctx, res);
return -1;
}
@@ -190,7 +202,7 @@ int samdb_search_string_multiple(TALLOC_CTX *mem_ctx,
}
(*strs)[count] = NULL;
- samdb_search_free(res);
+ samdb_search_free(mem_ctx, res);
return count;
}