1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-24 21:34:56 +03:00

r15663: Turn libnet_DeleteUser into async function and fix subtle bug probably

causing ejsnet test to segfault. Also, cleanup a bit and add monitor
fn pointer to internal user delete libnet function.
Time for some comments now.

rafal
This commit is contained in:
Rafal Szczesniak 2006-05-17 21:41:59 +00:00 committed by Gerald (Jerry) Carter
parent 2c9db94291
commit 89e9a88719
2 changed files with 142 additions and 94 deletions

View File

@ -39,7 +39,7 @@ struct create_user_state {
static void continue_rpc_useradd(struct composite_context *ctx); static void continue_rpc_useradd(struct composite_context *ctx);
static void continue_domain_open(struct composite_context *ctx); static void continue_domain_open_create(struct composite_context *ctx);
struct composite_context* libnet_CreateUser_send(struct libnet_context *ctx, struct composite_context* libnet_CreateUser_send(struct libnet_context *ctx,
@ -74,7 +74,7 @@ struct composite_context* libnet_CreateUser_send(struct libnet_context *ctx,
domopen_req = libnet_DomainOpen_send(ctx, &s->domain_open, monitor); domopen_req = libnet_DomainOpen_send(ctx, &s->domain_open, monitor);
if (composite_nomem(domopen_req, c)) return c; if (composite_nomem(domopen_req, c)) return c;
composite_continue(c, domopen_req, continue_domain_open, c); composite_continue(c, domopen_req, continue_domain_open_create, c);
return c; return c;
} else { } else {
/* no domain name provided - neither in io structure nor default /* no domain name provided - neither in io structure nor default
@ -93,7 +93,7 @@ struct composite_context* libnet_CreateUser_send(struct libnet_context *ctx,
domopen_req = libnet_DomainOpen_send(ctx, &s->domain_open, monitor); domopen_req = libnet_DomainOpen_send(ctx, &s->domain_open, monitor);
if (composite_nomem(domopen_req, c)) return c; if (composite_nomem(domopen_req, c)) return c;
composite_continue(c, domopen_req, continue_domain_open, c); composite_continue(c, domopen_req, continue_domain_open_create, c);
return c; return c;
} }
} }
@ -109,7 +109,7 @@ struct composite_context* libnet_CreateUser_send(struct libnet_context *ctx,
} }
static void continue_domain_open(struct composite_context *ctx) static void continue_domain_open_create(struct composite_context *ctx)
{ {
struct composite_context *c; struct composite_context *c;
struct create_user_state *s; struct create_user_state *s;
@ -178,101 +178,148 @@ NTSTATUS libnet_CreateUser(struct libnet_context *ctx, TALLOC_CTX *mem_ctx,
} }
#ifdef OBSOLETE
NTSTATUS libnet_CreateUser(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, struct libnet_CreateUser *r) struct delete_user_state {
struct libnet_DeleteUser r;
struct libnet_context *ctx;
struct libnet_DomainOpen domain_open;
struct libnet_rpc_userdel user_del;
/* information about the progress */
void (*monitor_fn)(struct monitor_msg *);
};
static void continue_rpc_userdel(struct composite_context *ctx);
static void continue_domain_open_delete(struct composite_context *ctx);
struct composite_context *libnet_DeleteUser_send(struct libnet_context *ctx,
TALLOC_CTX *mem_ctx,
struct libnet_DeleteUser *r,
void (*monitor)(struct monitor_msg*))
{
struct composite_context *c;
struct delete_user_state *s;
struct composite_context *domopen_req;
struct composite_context *delete_req;
c = talloc_zero(mem_ctx, struct composite_context);
if (c == NULL) return NULL;
s = talloc_zero(c, struct delete_user_state);
if (composite_nomem(s, c)) return c;
c->private_data = s;
c->state = COMPOSITE_STATE_IN_PROGRESS;
c->event_ctx = ctx->event_ctx;
s->ctx = ctx;
s->r = *r;
if (s->r.in.domain_name == NULL) {
if (policy_handle_empty(&ctx->domain.handle)) {
s->domain_open.in.domain_name = cli_credentials_get_domain(ctx->cred);
s->domain_open.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
domopen_req = libnet_DomainOpen_send(ctx, &s->domain_open, monitor);
if (composite_nomem(domopen_req, c)) return c;
composite_continue(c, domopen_req, continue_domain_open_delete, c);
return c;
}
} else {
if (policy_handle_empty(&ctx->domain.handle) ||
!strequal(s->r.in.domain_name, ctx->domain.name)) {
s->domain_open.in.domain_name = s->r.in.domain_name;
s->domain_open.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
domopen_req = libnet_DomainOpen_send(ctx, &s->domain_open, monitor);
if (composite_nomem(domopen_req, c)) return c;
composite_continue(c, domopen_req, continue_domain_open_delete, c);
return c;
}
}
s->user_del.in.username = r->in.user_name;
s->user_del.in.domain_handle = ctx->domain.handle;
delete_req = libnet_rpc_userdel_send(ctx->samr_pipe, &s->user_del, monitor);
if (composite_nomem(delete_req, c)) return c;
composite_continue(c, delete_req, continue_rpc_userdel, c);
return c;
}
static void continue_domain_open_delete(struct composite_context *ctx)
{
struct composite_context *c;
struct delete_user_state *s;
struct composite_context *delete_req;
struct monitor_msg msg;
c = talloc_get_type(ctx->async.private_data, struct composite_context);
s = talloc_get_type(c->private_data, struct delete_user_state);
c->status = libnet_DomainOpen_recv(ctx, s->ctx, c, &s->domain_open);
if (!composite_is_ok(c)) return;
if (s->monitor_fn) s->monitor_fn(&msg);
s->user_del.in.username = s->r.in.user_name;
s->user_del.in.domain_handle = s->ctx->domain.handle;
delete_req = libnet_rpc_userdel_send(s->ctx->samr_pipe, &s->user_del, s->monitor_fn);
if (composite_nomem(delete_req, c)) return;
composite_continue(c, delete_req, continue_rpc_userdel, c);
}
static void continue_rpc_userdel(struct composite_context *ctx)
{
struct composite_context *c;
struct delete_user_state *s;
struct monitor_msg msg;
c = talloc_get_type(ctx->async.private_data, struct composite_context);
s = talloc_get_type(c->private_data, struct delete_user_state);
c->status = libnet_rpc_userdel_recv(ctx, c, &s->user_del);
if (!composite_is_ok(c)) return;
if (s->monitor_fn) s->monitor_fn(&msg);
composite_done(c);
}
NTSTATUS libnet_DeleteUser_recv(struct composite_context *c, TALLOC_CTX *mem_ctx,
struct libnet_CreateUser *r)
{ {
NTSTATUS status; NTSTATUS status;
struct libnet_RpcConnect cn; struct delete_user_state *s;
struct libnet_DomainOpen dom_io;
struct libnet_rpc_useradd user_io;
/* connect rpc service of remote DC */ status = composite_wait(c);
cn.level = LIBNET_RPC_CONNECT_PDC;
cn.in.name = talloc_strdup(mem_ctx, r->in.domain_name);
cn.in.dcerpc_iface = &dcerpc_table_samr;
status = libnet_RpcConnect(ctx, mem_ctx, &cn);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
r->out.error_string = talloc_asprintf(mem_ctx, s = talloc_get_type(c->private_data, struct delete_user_state);
"Connection to SAMR pipe domain '%s' PDC failed: %s\n", r->out.error_string = talloc_steal(mem_ctx, s->r.out.error_string);
r->in.domain_name, nt_errstr(status));
return status;
} }
/* open connected domain */ r->out.error_string = NULL;
dom_io.in.domain_name = r->in.domain_name;
dom_io.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
status = libnet_DomainOpen(ctx, mem_ctx, &dom_io);
if (!NT_STATUS_IS_OK(status)) {
r->out.error_string = talloc_asprintf(mem_ctx,
"Creating user account failed: %s\n",
nt_errstr(status));
return status;
}
/* create user */
user_io.in.username = r->in.user_name;
user_io.in.domain_handle = dom_io.out.domain_handle;
status = libnet_rpc_useradd(ctx, mem_ctx, &user_io);
if (!NT_STATUS_IS_OK(status)) {
r->out.error_string = talloc_asprintf(mem_ctx,
"Creating user account failed: %s\n",
nt_errstr(status));
return status;
}
ctx->user_handle = user_io.out.user_handle;
return status; return status;
} }
#endif
NTSTATUS libnet_DeleteUser(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, struct libnet_DeleteUser *r) NTSTATUS libnet_DeleteUser(struct libnet_context *ctx, TALLOC_CTX *mem_ctx,
struct libnet_DeleteUser *r)
{ {
NTSTATUS status; struct composite_context *c;
struct libnet_RpcConnect cn;
struct libnet_DomainOpen dom_io;
struct libnet_rpc_userdel user_io;
/* connect rpc service of remote DC */ c = libnet_DeleteUser_send(ctx, mem_ctx, r, NULL);
cn.level = LIBNET_RPC_CONNECT_PDC; return libnet_DeleteUser_recv(c, mem_ctx, r);
cn.in.name = talloc_strdup(mem_ctx, r->in.domain_name);
cn.in.dcerpc_iface = &dcerpc_table_samr;
status = libnet_RpcConnect(ctx, mem_ctx, &cn);
if (!NT_STATUS_IS_OK(status)) {
r->out.error_string = talloc_asprintf(mem_ctx,
"Connection to SAMR pipe domain '%s' PDC failed: %s\n",
r->in.domain_name, nt_errstr(status));
return status;
}
/* open connected domain */
dom_io.in.domain_name = r->in.domain_name;
dom_io.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
status = libnet_DomainOpen(ctx, mem_ctx, &dom_io);
if (!NT_STATUS_IS_OK(status)) {
r->out.error_string = talloc_asprintf(mem_ctx,
"Opening domain to delete user account failed: %s\n",
nt_errstr(status));
return status;
}
/* create user */
user_io.in.username = r->in.user_name;
user_io.in.domain_handle = dom_io.out.domain_handle;
status = libnet_rpc_userdel(ctx, mem_ctx, &user_io);
if (!NT_STATUS_IS_OK(status)) {
r->out.error_string = talloc_asprintf(mem_ctx,
"Deleting user account failed: %s\n",
nt_errstr(status));
return status;
}
return status;
} }

View File

@ -369,7 +369,8 @@ static void userdel_handler(struct rpc_request *req)
*/ */
struct composite_context *libnet_rpc_userdel_send(struct dcerpc_pipe *p, struct composite_context *libnet_rpc_userdel_send(struct dcerpc_pipe *p,
struct libnet_rpc_userdel *io) struct libnet_rpc_userdel *io,
void (*monitor)(struct monitor_msg*))
{ {
struct composite_context *c; struct composite_context *c;
struct userdel_state *s; struct userdel_state *s;
@ -449,7 +450,7 @@ NTSTATUS libnet_rpc_userdel(struct dcerpc_pipe *p,
TALLOC_CTX *mem_ctx, TALLOC_CTX *mem_ctx,
struct libnet_rpc_userdel *io) struct libnet_rpc_userdel *io)
{ {
struct composite_context *c = libnet_rpc_userdel_send(p, io); struct composite_context *c = libnet_rpc_userdel_send(p, io, NULL);
return libnet_rpc_userdel_recv(c, mem_ctx, io); return libnet_rpc_userdel_recv(c, mem_ctx, io);
} }