1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

libnet: Make UserInfo accept a SID as input as well, fix wb_cmd_getpwuid

This commit is contained in:
Kai Blin 2008-04-19 14:09:18 +02:00
parent 8a8449c953
commit 5f3a70f285
6 changed files with 96 additions and 31 deletions

View File

@ -597,7 +597,9 @@ NTSTATUS libnet_ModifyUser(struct libnet_context *ctx, TALLOC_CTX *mem_ctx,
struct user_info_state {
struct libnet_context *ctx;
const char *domain_name;
enum libnet_UserInfo_level level;
const char *user_name;
const char *sid_string;
struct libnet_LookupName lookup;
struct libnet_DomainOpen domopen;
struct libnet_rpc_userinfo userinfo;
@ -628,7 +630,7 @@ struct composite_context* libnet_UserInfo_send(struct libnet_context *ctx,
{
struct composite_context *c;
struct user_info_state *s;
struct composite_context *lookup_req;
struct composite_context *lookup_req, *info_req;
bool prereq_met = false;
/* composite context allocation and setup */
@ -644,23 +646,54 @@ struct composite_context* libnet_UserInfo_send(struct libnet_context *ctx,
s->monitor_fn = monitor;
s->ctx = ctx;
s->domain_name = talloc_strdup(c, r->in.domain_name);
s->user_name = talloc_strdup(c, r->in.user_name);
s->level = r->in.level;
switch (s->level) {
case USER_INFO_BY_NAME:
s->user_name = talloc_strdup(c, r->in.data.user_name);
s->sid_string = NULL;
break;
case USER_INFO_BY_SID:
s->user_name = NULL;
s->sid_string = dom_sid_string(c, r->in.data.user_sid);
break;
}
/* prerequisite: make sure the domain is opened */
prereq_met = samr_domain_opened(ctx, s->domain_name, &c, &s->domopen,
continue_domain_open_info, monitor);
if (!prereq_met) return c;
/* prepare arguments for LookupName call */
s->lookup.in.domain_name = s->domain_name;
s->lookup.in.name = s->user_name;
switch (s->level) {
case USER_INFO_BY_NAME:
/* prepare arguments for LookupName call */
s->lookup.in.domain_name = s->domain_name;
s->lookup.in.name = s->user_name;
/* send the request */
lookup_req = libnet_LookupName_send(ctx, c, &s->lookup, s->monitor_fn);
if (composite_nomem(lookup_req, c)) return c;
/* send the request */
lookup_req = libnet_LookupName_send(ctx, c, &s->lookup,
s->monitor_fn);
if (composite_nomem(lookup_req, c)) return c;
/* set the next stage */
composite_continue(c, lookup_req, continue_name_found, c);
break;
case USER_INFO_BY_SID:
/* prepare arguments for UserInfo call */
s->userinfo.in.domain_handle = s->ctx->samr.handle;
s->userinfo.in.sid = s->sid_string;
s->userinfo.in.level = 21;
/* send the request */
info_req = libnet_rpc_userinfo_send(s->ctx->samr.pipe,
&s->userinfo,
s->monitor_fn);
if (composite_nomem(info_req, c)) return c;
/* set the next stage */
composite_continue(c, info_req, continue_info_received, c);
break;
}
/* set the next stage */
composite_continue(c, lookup_req, continue_name_found, c);
return c;
}
@ -673,7 +706,7 @@ static void continue_domain_open_info(struct composite_context *ctx)
{
struct composite_context *c;
struct user_info_state *s;
struct composite_context *lookup_req;
struct composite_context *lookup_req, *info_req;
struct monitor_msg msg;
c = talloc_get_type(ctx->async.private_data, struct composite_context);
@ -686,16 +719,36 @@ static void continue_domain_open_info(struct composite_context *ctx)
/* send monitor message */
if (s->monitor_fn) s->monitor_fn(&msg);
/* prepare arguments for LookupName call */
s->lookup.in.domain_name = s->domain_name;
s->lookup.in.name = s->user_name;
/* send the request */
lookup_req = libnet_LookupName_send(s->ctx, c, &s->lookup, s->monitor_fn);
if (composite_nomem(lookup_req, c)) return;
switch (s->level) {
case USER_INFO_BY_NAME:
/* prepare arguments for LookupName call */
s->lookup.in.domain_name = s->domain_name;
s->lookup.in.name = s->user_name;
/* set the next stage */
composite_continue(c, lookup_req, continue_name_found, c);
/* send the request */
lookup_req = libnet_LookupName_send(s->ctx, c, &s->lookup, s->monitor_fn);
if (composite_nomem(lookup_req, c)) return;
/* set the next stage */
composite_continue(c, lookup_req, continue_name_found, c);
break;
case USER_INFO_BY_SID:
/* prepare arguments for UserInfo call */
s->userinfo.in.domain_handle = s->ctx->samr.handle;
s->userinfo.in.sid = s->sid_string;
s->userinfo.in.level = 21;
/* send the request */
info_req = libnet_rpc_userinfo_send(s->ctx->samr.pipe,
&s->userinfo,
s->monitor_fn);
if (composite_nomem(info_req, c)) return;
/* set the next stage */
composite_continue(c, info_req, continue_info_received, c);
break;
}
}

View File

@ -99,11 +99,19 @@ struct libnet_ModifyUser {
} \
}
enum libnet_UserInfo_level {
USER_INFO_BY_NAME=0,
USER_INFO_BY_SID
};
struct libnet_UserInfo {
struct {
const char *user_name;
const char *domain_name;
enum libnet_UserInfo_level level;
union {
const char *user_name;
const struct dom_sid *user_sid;
} data;
} in;
struct {
struct dom_sid *user_sid;
@ -123,7 +131,6 @@ struct libnet_UserInfo {
struct timeval *last_logoff;
struct timeval *last_password_change;
uint32_t acct_flags;
const char *error_string;
} out;
};

View File

@ -268,8 +268,9 @@ static int ejs_net_userinfo(MprVarHandle eid, int argc, char **argv)
/* call the libnet function */
req.in.domain_name = userman_domain;
req.in.user_name = username;
req.in.data.user_name = username;
req.in.level = USER_INFO_BY_NAME;
status = libnet_UserInfo(ctx, mem_ctx, &req);
if (!NT_STATUS_IS_OK(status)) {
ejsSetErrorMsg(eid, "%s", req.out.error_string);

View File

@ -530,7 +530,8 @@ bool torture_modifyuser(struct torture_context *torture)
ZERO_STRUCT(user_req);
user_req.in.domain_name = lp_workgroup(torture->lp_ctx);
user_req.in.user_name = name;
user_req.in.data.user_name = name;
user_req.in.level = USER_INFO_BY_NAME;
status = libnet_UserInfo(ctx, torture, &user_req);
if (!NT_STATUS_IS_OK(status)) {
@ -642,7 +643,8 @@ bool torture_userinfo_api(struct torture_context *torture)
ZERO_STRUCT(req);
req.in.domain_name = domain_name.string;
req.in.user_name = name;
req.in.data.user_name = name;
req.in.level = USER_INFO_BY_NAME;
status = libnet_UserInfo(ctx, mem_ctx, &req);
if (!NT_STATUS_IS_OK(status)) {

View File

@ -92,7 +92,8 @@ static void cmd_getpwnam_recv_domain(struct composite_context *ctx)
return;
}
user_info->in.user_name = user_name;
user_info->in.level = USER_INFO_BY_NAME;
user_info->in.data.user_name = user_name;
user_info->in.domain_name = domain->libnet_ctx->samr.name;
state->workgroup_name = talloc_strdup(state,
domain->libnet_ctx->samr.name);

View File

@ -34,6 +34,7 @@ struct cmd_getpwuid_state {
struct composite_context *ctx;
struct wbsrv_service *service;
uid_t uid;
struct dom_sid *sid;
char *workgroup;
struct wbsrv_domain *domain;
@ -81,14 +82,13 @@ static void cmd_getpwuid_recv_sid(struct composite_context *ctx)
struct cmd_getpwuid_state *state =
talloc_get_type(ctx->async.private_data,
struct cmd_getpwuid_state);
struct dom_sid *sid;
DEBUG(5, ("cmd_getpwuid_recv_sid called %p\n", ctx->private_data));
state->ctx->status = wb_uid2sid_recv(ctx, state, &sid);
state->ctx->status = wb_uid2sid_recv(ctx, state, &state->sid);
if (!composite_is_ok(state->ctx)) return;
ctx = wb_sid2domain_send(state, state->service, sid);
ctx = wb_sid2domain_send(state, state->service, state->sid);
composite_continue(state->ctx, ctx, cmd_getpwuid_recv_domain, state);
}
@ -110,7 +110,8 @@ static void cmd_getpwuid_recv_domain(struct composite_context *ctx)
user_info = talloc(state, struct libnet_UserInfo);
if (composite_nomem(user_info, state->ctx)) return;
user_info->in.user_name = state->domain->libnet_ctx->cred->username;
user_info->in.level = USER_INFO_BY_SID;
user_info->in.data.user_sid = state->sid;
user_info->in.domain_name = state->domain->libnet_ctx->samr.name;
/* We need the workgroup later, so copy it */