s3/docs: Correct version number.
[Samba/gebeck_regimport.git] / source4 / winbind / wb_cmd_setpwent.c
blob50ab2fdff61f4548f609fd35f38be6aa5a00dde0
1 /*
2 Unix SMB/CIFS implementation.
4 Command backend for setpwent
6 Copyright (C) Kai Blin 2007
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "includes.h"
23 #include "libcli/composite/composite.h"
24 #include "winbind/wb_server.h"
25 #include "winbind/wb_async_helpers.h"
26 #include "winbind/wb_helper.h"
27 #include "smbd/service_task.h"
28 #include "libnet/libnet_proto.h"
30 struct cmd_setpwent_state {
31 struct composite_context *ctx;
32 struct wbsrv_service *service;
33 struct libnet_context *libnet_ctx;
35 struct wbsrv_pwent *result;
38 static void cmd_setpwent_recv_domain(struct composite_context *ctx);
39 static void cmd_setpwent_recv_user_list(struct composite_context *ctx);
41 struct composite_context *wb_cmd_setpwent_send(TALLOC_CTX *mem_ctx,
42 struct wbsrv_service *service)
44 struct composite_context *ctx, *result;
45 struct cmd_setpwent_state *state;
47 DEBUG(5, ("wb_cmd_setpwent_send called\n"));
49 result = composite_create(mem_ctx, service->task->event_ctx);
50 if (!result) return NULL;
52 state = talloc(mem_ctx, struct cmd_setpwent_state);
53 if (composite_nomem(state, result)) return result;
55 state->ctx = result;
56 result->private_data = state;
57 state->service = service;
59 state->result = talloc(state, struct wbsrv_pwent);
60 if (composite_nomem(state->result, state->ctx)) return result;
62 ctx = wb_sid2domain_send(state, service, service->primary_sid);
63 if (composite_nomem(ctx, state->ctx)) return result;
65 composite_continue(state->ctx, ctx, cmd_setpwent_recv_domain, state);
66 return result;
69 static void cmd_setpwent_recv_domain(struct composite_context *ctx)
71 struct cmd_setpwent_state *state = talloc_get_type(
72 ctx->async.private_data, struct cmd_setpwent_state);
73 struct wbsrv_domain *domain;
74 struct libnet_UserList *user_list;
76 DEBUG(5, ("cmd_setpwent_recv_domain called\n"));
78 state->ctx->status = wb_sid2domain_recv(ctx, &domain);
79 if (!composite_is_ok(state->ctx)) return;
81 state->libnet_ctx = domain->libnet_ctx;
83 user_list = talloc(state->result, struct libnet_UserList);
84 if (composite_nomem(user_list, state->ctx)) return;
86 user_list->in.domain_name = talloc_strdup(state,
87 domain->libnet_ctx->samr.name);
88 if (composite_nomem(user_list->in.domain_name, state->ctx)) return;
90 /* Page size recommended by Rafal */
91 user_list->in.page_size = 128;
93 /* Always get the start of the list */
94 user_list->in.resume_index = 0;
96 ctx = libnet_UserList_send(domain->libnet_ctx, state->result, user_list,
97 NULL);
99 composite_continue(state->ctx, ctx, cmd_setpwent_recv_user_list, state);
102 static void cmd_setpwent_recv_user_list(struct composite_context *ctx)
104 struct cmd_setpwent_state *state = talloc_get_type(
105 ctx->async.private_data, struct cmd_setpwent_state);
106 struct libnet_UserList *user_list;
108 DEBUG(5, ("cmd_setpwent_recv_user_list called\n"));
110 user_list = talloc(state->result, struct libnet_UserList);
111 if (composite_nomem(user_list, state->ctx)) return;
113 state->ctx->status = libnet_UserList_recv(ctx, state->result,
114 user_list);
115 if (!composite_is_ok(state->ctx)) return;
117 state->result->user_list = user_list;
118 state->result->page_index = 0;
119 state->result->libnet_ctx = state->libnet_ctx;
121 composite_done(state->ctx);
124 NTSTATUS wb_cmd_setpwent_recv(struct composite_context *ctx,
125 TALLOC_CTX *mem_ctx, struct wbsrv_pwent **pwent)
127 NTSTATUS status = composite_wait(ctx);
129 DEBUG(5, ("wb_cmd_setpwent_recv called\n"));
131 if (NT_STATUS_IS_OK(status)) {
132 struct cmd_setpwent_state *state =
133 talloc_get_type(ctx->private_data,
134 struct cmd_setpwent_state);
136 *pwent = talloc_steal(mem_ctx, state->result);
139 talloc_free(ctx);
140 return status;