/*
Unix SMB/CIFS implementation.
- Copyright (C) Rafal Szczesniak <mimir@samba.org> 2005
+ Copyright (C) Rafal Szczesniak 2005
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
+ the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
struct composite_context *c;
struct create_user_state *s;
struct composite_context *create_req;
- BOOL prereq_met = False;
+ bool prereq_met = false;
/* composite context allocation and setup */
c = composite_create(mem_ctx, ctx->event_ctx);
struct composite_context *c;
struct delete_user_state *s;
struct composite_context *delete_req;
- BOOL prereq_met = False;
+ bool prereq_met = false;
/* composite context allocation and setup */
c = composite_create(mem_ctx, ctx->event_ctx);
struct composite_context *c;
struct modify_user_state *s;
struct composite_context *userinfo_req;
- BOOL prereq_met = False;
+ bool prereq_met = false;
c = composite_create(mem_ctx, ctx->event_ctx);
if (c == NULL) return NULL;
/* account expiry change */
SET_FIELD_NTTIME(r->in, user, mod, acct_expiry, USERMOD_FIELD_ACCT_EXPIRY);
+ /* account flags change */
+ SET_FIELD_ACCT_FLAGS(r->in, user, mod, acct_flags, USERMOD_FIELD_ACCT_FLAGS);
+
return NT_STATUS_OK;
}
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;
{
struct composite_context *c;
struct user_info_state *s;
- struct composite_context *lookup_req;
- BOOL prereq_met = False;
+ struct composite_context *lookup_req, *info_req;
+ bool prereq_met = false;
/* composite context allocation and setup */
c = composite_create(mem_ctx, ctx->event_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;
-
- /* send the request */
- lookup_req = libnet_LookupName_send(ctx, c, &s->lookup, s->monitor_fn);
- if (composite_nomem(lookup_req, c)) return c;
+ 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;
+
+ /* 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;
}
{
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);
/* 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;
-
- /* set the next stage */
- composite_continue(c, lookup_req, continue_name_found, c);
+ 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(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;
+ }
}
s = talloc_get_type(c->private_data, struct user_info_state);
info = &s->userinfo.out.info.info21;
+ r->out.user_sid = dom_sid_add_rid(mem_ctx, s->ctx->samr.sid, info->rid);
+ r->out.primary_group_sid = dom_sid_add_rid(mem_ctx, s->ctx->samr.sid, info->primary_gid);
+
/* string fields */
r->out.account_name = talloc_steal(mem_ctx, info->account_name.string);
r->out.full_name = talloc_steal(mem_ctx, info->full_name.string);
*
* @param ctx initialised libnet context
* @param mem_ctx memory context of this call
- * @param r pointer to a structure containing arguments and results of this call
+ * @param r pointer to structure containing arguments and results of this call
* @param monitor function pointer for receiving monitor messages
* @return compostite context of this request
*/
struct composite_context *c;
struct userlist_state *s;
struct rpc_request *query_req;
- BOOL prereq_met = False;
+ bool prereq_met = false;
/* composite context allocation and setup */
c = composite_create(mem_ctx, ctx->event_ctx);
/* store the arguments in the state structure */
s->ctx = ctx;
s->page_size = r->in.page_size;
- s->resume_index = (uint32_t)r->in.resume_index;
+ s->resume_index = r->in.resume_index;
s->domain_name = talloc_strdup(c, r->in.domain_name);
s->monitor_fn = monitor;
/* prepare arguments of QueryDomainInfo call */
s->query_domain.in.handle = &ctx->lsa.handle;
s->query_domain.in.level = LSA_POLICY_INFO_DOMAIN;
-
+ s->query_domain.out.info = talloc_zero(c, union lsa_PolicyInformation *);
+ if (composite_nomem(s->query_domain.out.info, c)) return c;
+
/* send the request */
query_req = dcerpc_lsa_QueryInfoPolicy_send(ctx->lsa.pipe, c, &s->query_domain);
if (composite_nomem(query_req, c)) return c;
/* prepare arguments of QueryDomainInfo call */
s->query_domain.in.handle = &s->ctx->lsa.handle;
s->query_domain.in.level = LSA_POLICY_INFO_DOMAIN;
+ s->query_domain.out.info = talloc_zero(c, union lsa_PolicyInformation *);
+ if (composite_nomem(s->query_domain.out.info, c)) return;
/* send the request */
query_req = dcerpc_lsa_QueryInfoPolicy_send(s->ctx->lsa.pipe, c, &s->query_domain);
struct composite_context *c;
struct userlist_state *s;
struct rpc_request *enum_req;
- BOOL prereq_met = False;
+ bool prereq_met = false;
- c = talloc_get_type(req->async.private, struct composite_context);
+ c = talloc_get_type(req->async.private_data, struct composite_context);
s = talloc_get_type(c->private_data, struct userlist_state);
/* receive result of rpc request */
- c->status = dcerpc_ndr_request_recv(req);
+ c->status = dcerpc_lsa_QueryInfoPolicy_recv(req);
if (!composite_is_ok(c)) return;
/* get the returned domain info */
- s->dominfo = s->query_domain.out.info->domain;
+ s->dominfo = (*s->query_domain.out.info)->domain;
/* make sure we have samr domain handle before continuing */
prereq_met = samr_domain_opened(s->ctx, s->domain_name, &c, &s->domain_open,
continue_samr_domain_opened, s->monitor_fn);
if (!prereq_met) return;
- /* prepare arguments od EnumDomainUsers call */
+ /* prepare arguments of EnumDomainUsers call */
s->user_list.in.domain_handle = &s->ctx->samr.handle;
s->user_list.in.max_size = s->page_size;
s->user_list.in.resume_handle = &s->resume_index;
s->user_list.in.acct_flags = ACB_NORMAL;
s->user_list.out.resume_handle = &s->resume_index;
+ s->user_list.out.num_entries = talloc(s, uint32_t);
+ if (composite_nomem(s->user_list.out.num_entries, c)) return;
+ s->user_list.out.sam = talloc(s, struct samr_SamArray *);
+ if (composite_nomem(s->user_list.out.sam, c)) return;
/* send the request */
enum_req = dcerpc_samr_EnumDomainUsers_send(s->ctx->samr.pipe, c, &s->user_list);
c->status = libnet_DomainOpen_recv(ctx, s->ctx, c, &s->domain_open);
if (!composite_is_ok(c)) return;
- /* prepare arguments od EnumDomainUsers call */
+ /* prepare arguments of EnumDomainUsers call */
s->user_list.in.domain_handle = &s->ctx->samr.handle;
s->user_list.in.max_size = s->page_size;
s->user_list.in.resume_handle = &s->resume_index;
s->user_list.in.acct_flags = ACB_NORMAL;
s->user_list.out.resume_handle = &s->resume_index;
+ s->user_list.out.sam = talloc(s, struct samr_SamArray *);
+ if (composite_nomem(s->user_list.out.sam, c)) return;
+ s->user_list.out.num_entries = talloc(s, uint32_t);
+ if (composite_nomem(s->user_list.out.num_entries, c)) return;
/* send the request */
enum_req = dcerpc_samr_EnumDomainUsers_send(s->ctx->samr.pipe, c, &s->user_list);
struct userlist_state *s;
int i;
- c = talloc_get_type(req->async.private, struct composite_context);
+ c = talloc_get_type(req->async.private_data, struct composite_context);
s = talloc_get_type(c->private_data, struct userlist_state);
/* receive result of rpc request */
- c->status = dcerpc_ndr_request_recv(req);
+ c->status = dcerpc_samr_EnumDomainUsers_recv(req);
if (!composite_is_ok(c)) return;
- /* get the actual status of the rpc call result (instead of rpc layer status) */
+ /* get the actual status of the rpc call result
+ (instead of rpc layer status) */
c->status = s->user_list.out.result;
- /* we're interested in status "ok" as well as two enum-specific status codes */
+ /* we're interested in status "ok" as well as two
+ enum-specific status codes */
if (NT_STATUS_IS_OK(c->status) ||
NT_STATUS_EQUAL(c->status, STATUS_MORE_ENTRIES) ||
NT_STATUS_EQUAL(c->status, NT_STATUS_NO_MORE_ENTRIES)) {
/* get enumerated accounts counter and resume handle (the latter allows
making subsequent call to continue enumeration) */
s->resume_index = *s->user_list.out.resume_handle;
- s->count = s->user_list.out.num_entries;
+ s->count = *s->user_list.out.num_entries;
/* prepare returned user accounts array */
- s->users = talloc_array(c, struct userlist, s->user_list.out.sam->count);
+ s->users = talloc_array(c, struct userlist, (*s->user_list.out.sam)->count);
if (composite_nomem(s->users, c)) return;
- for (i = 0; i < s->user_list.out.sam->count; i++) {
+ for (i = 0; i < (*s->user_list.out.sam)->count; i++) {
struct dom_sid *user_sid;
- struct samr_SamEntry *entry = &s->user_list.out.sam->entries[i];
- struct dom_sid *domain_sid = s->query_domain.out.info->domain.sid;
+ struct samr_SamEntry *entry = &(*s->user_list.out.sam)->entries[i];
+ struct dom_sid *domain_sid = (*s->query_domain.out.info)->domain.sid;
/* construct user sid from returned rid and queried domain sid */
user_sid = dom_sid_add_rid(c, domain_sid, entry->idx);
*
* @param c composite context returned by send request routine
* @param mem_ctx memory context of this call
- * @param r pointer to a structure containing arguments and result of this call
+ * @param r pointer to structure containing arguments and result of this call
* @return nt status
*/
NTSTATUS libnet_UserList_recv(struct composite_context* c, TALLOC_CTX *mem_ctx,
*
* @param ctx initialised libnet context
* @param mem_ctx memory context of this call
- * @param r pointer to a structure containing arguments and result of this call
+ * @param r pointer to structure containing arguments and result of this call
* @return nt status
*/
NTSTATUS libnet_UserList(struct libnet_context *ctx,