mirror of
https://github.com/samba-team/samba.git
synced 2025-12-02 00:23:50 +03:00
r15919: - Create function checking prerequisites like valid domain
opened and rpc pipe connected. Each user management routine calls the function before doing their job - Initial work on user modify functionality (does nothing yet) rafal
This commit is contained in:
committed by
Gerald (Jerry) Carter
parent
4298fde656
commit
51501cdeef
@@ -27,6 +27,57 @@
|
||||
#include "librpc/gen_ndr/ndr_samr.h"
|
||||
|
||||
|
||||
/**
|
||||
* Verify, before actually doing anything with user accounts, whether
|
||||
* required domain is already opened and thus ready for operation.
|
||||
* If it is not, or if the opened domain is not the one requested, open
|
||||
* the requested domain.
|
||||
*/
|
||||
static struct composite_context* domain_opened(struct libnet_context *ctx,
|
||||
const char *domain_name,
|
||||
struct composite_context *parent_ctx,
|
||||
struct libnet_DomainOpen *domain_open,
|
||||
void (*continue_fn)(struct composite_context*),
|
||||
void (*monitor)(struct monitor_msg*))
|
||||
{
|
||||
struct composite_context *domopen_req;
|
||||
|
||||
if (domain_name == NULL) {
|
||||
if (policy_handle_empty(&ctx->domain.handle)) {
|
||||
domain_open->in.domain_name = cli_credentials_get_domain(ctx->cred);
|
||||
domain_open->in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
|
||||
|
||||
domopen_req = libnet_DomainOpen_send(ctx, domain_open, monitor);
|
||||
if (composite_nomem(domopen_req, parent_ctx)) return parent_ctx;
|
||||
|
||||
composite_continue(parent_ctx, domopen_req, continue_fn, parent_ctx);
|
||||
return parent_ctx;
|
||||
|
||||
} else {
|
||||
composite_error(parent_ctx, NT_STATUS_INVALID_PARAMETER);
|
||||
return parent_ctx;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if (policy_handle_empty(&ctx->domain.handle) ||
|
||||
!strequal(domain_name, ctx->domain.name)) {
|
||||
domain_open->in.domain_name = domain_name;
|
||||
domain_open->in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
|
||||
|
||||
domopen_req = libnet_DomainOpen_send(ctx, domain_open, monitor);
|
||||
if (composite_nomem(domopen_req, parent_ctx)) return parent_ctx;
|
||||
|
||||
composite_continue(parent_ctx, domopen_req, continue_fn, parent_ctx);
|
||||
return parent_ctx;
|
||||
}
|
||||
}
|
||||
|
||||
/* domain has already been opened and it's the same domain as requested */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
struct create_user_state {
|
||||
struct libnet_CreateUser r;
|
||||
struct libnet_DomainOpen domain_open;
|
||||
@@ -50,7 +101,7 @@ struct composite_context* libnet_CreateUser_send(struct libnet_context *ctx,
|
||||
struct composite_context *c;
|
||||
struct create_user_state *s;
|
||||
struct composite_context *create_req;
|
||||
struct composite_context *domopen_req;
|
||||
struct composite_context *prereq_ctx;
|
||||
|
||||
c = talloc_zero(mem_ctx, struct composite_context);
|
||||
if (c == NULL) return NULL;
|
||||
@@ -66,38 +117,9 @@ struct composite_context* libnet_CreateUser_send(struct libnet_context *ctx,
|
||||
s->r = *r;
|
||||
ZERO_STRUCT(s->r.out);
|
||||
|
||||
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_create, c);
|
||||
return c;
|
||||
} else {
|
||||
/* no domain name provided - neither in io structure nor default
|
||||
stored in libnet context - report an error */
|
||||
composite_error(c, NT_STATUS_INVALID_PARAMETER);
|
||||
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_create, c);
|
||||
return c;
|
||||
}
|
||||
}
|
||||
prereq_ctx = domain_opened(ctx, s->r.in.domain_name, c, &s->domain_open,
|
||||
continue_domain_open_create, monitor);
|
||||
if (prereq_ctx) return prereq_ctx;
|
||||
|
||||
s->user_add.in.username = r->in.user_name;
|
||||
s->user_add.in.domain_handle = ctx->domain.handle;
|
||||
@@ -158,12 +180,14 @@ NTSTATUS libnet_CreateUser_recv(struct composite_context *c, TALLOC_CTX *mem_ctx
|
||||
NTSTATUS status;
|
||||
struct create_user_state *s;
|
||||
|
||||
r->out.error_string = NULL;
|
||||
|
||||
status = composite_wait(c);
|
||||
if (NT_STATUS_IS_OK(status)) {
|
||||
r->out.error_string = NULL;
|
||||
} else {
|
||||
s = talloc_get_type(c->private_data, struct create_user_state);
|
||||
r->out.error_string = talloc_steal(mem_ctx, s->r.out.error_string);
|
||||
r->out.error_string = talloc_strdup(mem_ctx, nt_errstr(status));
|
||||
}
|
||||
|
||||
return status;
|
||||
@@ -180,7 +204,6 @@ NTSTATUS libnet_CreateUser(struct libnet_context *ctx, TALLOC_CTX *mem_ctx,
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct delete_user_state {
|
||||
struct libnet_DeleteUser r;
|
||||
struct libnet_context *ctx;
|
||||
@@ -203,8 +226,8 @@ struct composite_context *libnet_DeleteUser_send(struct libnet_context *ctx,
|
||||
{
|
||||
struct composite_context *c;
|
||||
struct delete_user_state *s;
|
||||
struct composite_context *domopen_req;
|
||||
struct composite_context *delete_req;
|
||||
struct composite_context *prereq_ctx;
|
||||
|
||||
c = talloc_zero(mem_ctx, struct composite_context);
|
||||
if (c == NULL) return NULL;
|
||||
@@ -220,33 +243,9 @@ struct composite_context *libnet_DeleteUser_send(struct libnet_context *ctx,
|
||||
s->r = *r;
|
||||
ZERO_STRUCT(s->r.out);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
prereq_ctx = domain_opened(ctx, s->r.in.domain_name, c, &s->domain_open,
|
||||
continue_domain_open_delete, monitor);
|
||||
if (prereq_ctx) return prereq_ctx;
|
||||
|
||||
s->user_del.in.username = r->in.user_name;
|
||||
s->user_del.in.domain_handle = ctx->domain.handle;
|
||||
@@ -327,3 +326,116 @@ NTSTATUS libnet_DeleteUser(struct libnet_context *ctx, TALLOC_CTX *mem_ctx,
|
||||
c = libnet_DeleteUser_send(ctx, mem_ctx, r, NULL);
|
||||
return libnet_DeleteUser_recv(c, mem_ctx, r);
|
||||
}
|
||||
|
||||
|
||||
struct modify_user_state {
|
||||
struct libnet_ModifyUser r;
|
||||
struct libnet_context *ctx;
|
||||
struct libnet_DomainOpen domain_open;
|
||||
struct libnet_rpc_usermod user_mod;
|
||||
|
||||
void (*monitor_fn)(struct monitor_msg *);
|
||||
};
|
||||
|
||||
|
||||
static void continue_rpc_usermod(struct composite_context *ctx);
|
||||
static void continue_domain_open_modify(struct composite_context *ctx);
|
||||
|
||||
|
||||
struct composite_context *libnet_ModifyUser_send(struct libnet_context *ctx,
|
||||
TALLOC_CTX *mem_ctx,
|
||||
struct libnet_ModifyUser *r,
|
||||
void (*monitor)(struct monitor_msg*))
|
||||
{
|
||||
struct composite_context *c;
|
||||
struct modify_user_state *s;
|
||||
struct composite_context *domopen_req;
|
||||
struct composite_context *create_req;
|
||||
struct composite_context *prereq_ctx;
|
||||
|
||||
c = talloc_zero(mem_ctx, struct composite_context);
|
||||
if (c == NULL) return NULL;
|
||||
|
||||
s = talloc_zero(c, struct modify_user_state);
|
||||
if (composite_nomem(s, c)) return c;
|
||||
|
||||
c->state = COMPOSITE_STATE_IN_PROGRESS;
|
||||
c->private_data = s;
|
||||
c->event_ctx = ctx->event_ctx;
|
||||
|
||||
s->ctx = ctx;
|
||||
s->r = *r;
|
||||
|
||||
prereq_ctx = domain_opened(ctx, s->r.in.domain_name, c, &s->domain_open,
|
||||
continue_domain_open_modify, monitor);
|
||||
if (prereq_ctx) return prereq_ctx;
|
||||
|
||||
s->user_mod.in.username = r->in.user_name;
|
||||
s->user_mod.in.domain_handle = ctx->domain.handle;
|
||||
|
||||
create_req = libnet_rpc_usermod_send(ctx->samr_pipe, &s->user_mod, monitor);
|
||||
if (composite_nomem(create_req, c)) return c;
|
||||
|
||||
composite_continue(c, create_req, continue_rpc_usermod, c);
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
static void continue_domain_open_modify(struct composite_context *ctx)
|
||||
{
|
||||
struct composite_context *c;
|
||||
struct modify_user_state *s;
|
||||
struct composite_context *modify_req;
|
||||
struct monitor_msg msg;
|
||||
|
||||
c = talloc_get_type(ctx->async.private_data, struct composite_context);
|
||||
s = talloc_get_type(c->private_data, struct modify_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_mod.in.username = s->r.in.user_name;
|
||||
s->user_mod.in.domain_handle = s->ctx->domain.handle;
|
||||
|
||||
modify_req = libnet_rpc_usermod_send(s->ctx->samr_pipe, &s->user_mod, s->monitor_fn);
|
||||
if (composite_nomem(modify_req, c)) return;
|
||||
|
||||
composite_continue(c, modify_req, continue_rpc_usermod, c);
|
||||
}
|
||||
|
||||
|
||||
static void continue_rpc_usermod(struct composite_context *ctx)
|
||||
{
|
||||
struct composite_context *c;
|
||||
struct modify_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 modify_user_state);
|
||||
|
||||
c->status = libnet_rpc_usermod_recv(ctx, c, &s->user_mod);
|
||||
if (!composite_is_ok(c)) return;
|
||||
|
||||
if (s->monitor_fn) s->monitor_fn(&msg);
|
||||
composite_done(c);
|
||||
}
|
||||
|
||||
|
||||
NTSTATUS libnet_ModifyUser_recv(struct composite_context *c, TALLOC_CTX *mem_ctx,
|
||||
struct libnet_ModifyUser *r)
|
||||
{
|
||||
NTSTATUS status = composite_wait(c);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
NTSTATUS libnet_ModifyUser(struct libnet_context *ctx, TALLOC_CTX *mem_ctx,
|
||||
struct libnet_ModifyUser *r)
|
||||
{
|
||||
struct composite_context *c;
|
||||
|
||||
c = libnet_ModifyUser_send(ctx, mem_ctx, r, NULL);
|
||||
return libnet_ModifyUser_recv(c, mem_ctx, r);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user