r9994: Unused variable.
[bbaumbach/samba-autobuild/.git] / source4 / libnet / userman.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    Copyright (C) Rafal Szczesniak 2005
5    
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 /*
22   a composite functions for user management operations (add/del/chg)
23 */
24
25 #include "includes.h"
26 #include "libcli/raw/libcliraw.h"
27 #include "libcli/composite/composite.h"
28 #include "libcli/composite/monitor.h"
29 #include "librpc/gen_ndr/ndr_samr.h"
30 #include "libnet/composite.h"
31 #include "libnet/userman.h"
32 #include "libnet/userinfo.h"
33
34 /*
35  * Composite user add function
36  */
37
38 static void useradd_handler(struct rpc_request*);
39
40 enum useradd_stage { USERADD_CREATE };
41
42 struct useradd_state {
43         enum useradd_stage       stage;
44         struct dcerpc_pipe       *pipe;
45         struct rpc_request       *req;
46         struct policy_handle     domain_handle;
47         struct samr_CreateUser   createuser;
48         struct policy_handle     user_handle;
49         uint32_t                 user_rid;
50 };
51
52
53 /**
54  * Stage 1 (and the only one for now): Create user account.
55  */
56 static NTSTATUS useradd_create(struct composite_context *c,
57                                struct useradd_state *s)
58 {
59         c->status = dcerpc_ndr_request_recv(s->req);
60         NT_STATUS_NOT_OK_RETURN(c->status);
61         
62         c->state = SMBCLI_REQUEST_DONE;
63         return NT_STATUS_OK;
64 }
65
66
67 /**
68  * Event handler for asynchronous request. Handles transition through
69  * intermediate stages of the call.
70  *
71  * @param req rpc call context
72  */
73 static void useradd_handler(struct rpc_request *req)
74 {
75         struct composite_context *c = req->async.private;
76         struct useradd_state *s = talloc_get_type(c->private, struct useradd_state);
77         struct monitor_msg msg;
78         struct msg_rpc_create_user *rpc_create;
79         
80         switch (s->stage) {
81         case USERADD_CREATE:
82                 c->status = useradd_create(c, s);
83
84                 msg.type = rpc_create_user;
85                 rpc_create = talloc(s, struct msg_rpc_create_user);
86                 rpc_create->rid = *s->createuser.out.rid;
87                 msg.data = (void*)rpc_create;
88                 msg.data_size = sizeof(*rpc_create);
89                 break;
90         }
91
92         if (!NT_STATUS_IS_OK(c->status)) {
93                 c->state = SMBCLI_REQUEST_ERROR;
94         }
95
96         if (c->monitor_fn) {
97                 c->monitor_fn(&msg);
98         }
99
100         if (c->state >= SMBCLI_REQUEST_DONE &&
101             c->async.fn) {
102                 c->async.fn(c);
103         }
104 }
105
106
107 /**
108  * Sends asynchronous useradd request
109  *
110  * @param p dce/rpc call pipe 
111  * @param io arguments and results of the call
112  */
113
114 struct composite_context *libnet_rpc_useradd_send(struct dcerpc_pipe *p,
115                                                   struct libnet_rpc_useradd *io,
116                                                   void (*monitor)(struct monitor_msg*))
117 {
118         struct composite_context *c;
119         struct useradd_state *s;
120         
121         c = talloc_zero(p, struct composite_context);
122         if (c == NULL) goto failure;
123         
124         s = talloc_zero(c, struct useradd_state);
125         if (s == NULL) goto failure;
126         
127         s->domain_handle = io->in.domain_handle;
128         s->pipe          = p;
129         
130         c->state       = SMBCLI_REQUEST_SEND;
131         c->private     = s;
132         c->event_ctx   = dcerpc_event_context(p);
133         c->monitor_fn  = monitor;
134
135         /* preparing parameters to send rpc request */
136         s->createuser.in.domain_handle         = &io->in.domain_handle;
137         s->createuser.in.account_name          = talloc_zero(c, struct lsa_String);
138         s->createuser.in.account_name->string  = talloc_strdup(c, io->in.username);
139         s->createuser.out.user_handle          = &s->user_handle;
140         s->createuser.out.rid                  = &s->user_rid;
141
142         /* send request */
143         s->req = dcerpc_samr_CreateUser_send(p, c, &s->createuser);
144
145         /* callback handler */
146         s->req->async.callback = useradd_handler;
147         s->req->async.private  = c;
148         s->stage = USERADD_CREATE;
149
150         return c;
151         
152 failure:
153         talloc_free(c);
154         return NULL;
155 }
156
157
158 /**
159  * Waits for and receives result of asynchronous useradd call
160  * 
161  * @param c composite context returned by asynchronous useradd call
162  * @param mem_ctx memory context of the call
163  * @param io pointer to results (and arguments) of the call
164  * @return nt status code of execution
165  */
166
167 NTSTATUS libnet_rpc_useradd_recv(struct composite_context *c, TALLOC_CTX *mem_ctx,
168                                     struct libnet_rpc_useradd *io)
169 {
170         NTSTATUS status;
171         struct useradd_state *s;
172         
173         status = composite_wait(c);
174         
175         if (NT_STATUS_IS_OK(status) && io) {
176                 /* get and return result of the call */
177                 s = talloc_get_type(c->private, struct useradd_state);
178                 io->out.user_handle = s->user_handle;
179         }
180
181         talloc_free(c);
182         return status;
183 }
184
185
186 /**
187  * Synchronous version of useradd call
188  *
189  * @param pipe dce/rpc call pipe
190  * @param mem_ctx memory context for the call
191  * @param io arguments and results of the call
192  * @return nt status code of execution
193  */
194
195 NTSTATUS libnet_rpc_useradd(struct dcerpc_pipe *pipe,
196                                TALLOC_CTX *mem_ctx,
197                                struct libnet_rpc_useradd *io)
198 {
199         struct composite_context *c = libnet_rpc_useradd_send(pipe, io, NULL);
200         return libnet_rpc_useradd_recv(c, mem_ctx, io);
201 }
202
203
204 /*
205  * Composite user delete function
206  */
207
208 static void userdel_handler(struct rpc_request*);
209
210 enum userdel_stage { USERDEL_LOOKUP, USERDEL_OPEN, USERDEL_DELETE };
211
212 struct userdel_state {
213         enum userdel_stage        stage;
214         struct dcerpc_pipe        *pipe;
215         struct rpc_request        *req;
216         struct policy_handle      domain_handle;
217         struct policy_handle      user_handle;
218         struct samr_LookupNames   lookupname;
219         struct samr_OpenUser      openuser;
220         struct samr_DeleteUser    deleteuser;
221 };
222
223
224 /**
225  * Stage 1: Lookup the user name and resolve it to rid
226  */
227 static NTSTATUS userdel_lookup(struct composite_context *c,
228                                struct userdel_state *s)
229 {
230         NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
231
232         c->status = dcerpc_ndr_request_recv(s->req);
233         NT_STATUS_NOT_OK_RETURN(c->status);
234         
235         if (!s->lookupname.out.rids.count) {
236                 /* TODO: no such user */
237                 status = NT_STATUS_NO_SUCH_USER;
238
239         } else if (!s->lookupname.out.rids.count > 1) {
240                 /* TODO: ambiguous username */
241                 status = NT_STATUS_INVALID_ACCOUNT_NAME;
242         }
243         
244         s->openuser.in.domain_handle = &s->domain_handle;
245         s->openuser.in.rid           = s->lookupname.out.rids.ids[0];
246         s->openuser.in.access_mask   = SEC_FLAG_MAXIMUM_ALLOWED;
247         s->openuser.out.user_handle  = &s->user_handle;
248
249         s->req = dcerpc_samr_OpenUser_send(s->pipe, c, &s->openuser);
250         
251         s->req->async.callback = userdel_handler;
252         s->req->async.private  = c;
253         s->stage = USERDEL_OPEN;
254         
255         return NT_STATUS_OK;
256 }
257
258
259 /**
260  * Stage 2: Open user account.
261  */
262 static NTSTATUS userdel_open(struct composite_context *c,
263                              struct userdel_state *s)
264 {
265         c->status = dcerpc_ndr_request_recv(s->req);
266         NT_STATUS_NOT_OK_RETURN(c->status);
267         
268         s->deleteuser.in.user_handle   = &s->user_handle;
269         s->deleteuser.out.user_handle  = &s->user_handle;
270         
271         s->req = dcerpc_samr_DeleteUser_send(s->pipe, c, &s->deleteuser);
272         
273         s->req->async.callback = userdel_handler;
274         s->req->async.private  = c;
275         s->stage = USERDEL_DELETE;
276         
277         return NT_STATUS_OK;
278 }
279
280
281 /**
282  * Stage 3: Delete user account
283  */
284 static NTSTATUS userdel_delete(struct composite_context *c,
285                                struct userdel_state *s)
286 {
287         c->status = dcerpc_ndr_request_recv(s->req);
288         NT_STATUS_NOT_OK_RETURN(c->status);
289         
290         c->state = SMBCLI_REQUEST_DONE;
291
292         return NT_STATUS_OK;
293 }
294
295
296 /**
297  * Event handler for asynchronous request. Handles transition through
298  * intermediate stages of the call.
299  *
300  * @param req rpc call context
301  */
302 static void userdel_handler(struct rpc_request *req)
303 {
304         struct composite_context *c = req->async.private;
305         struct userdel_state *s = talloc_get_type(c->private, struct userdel_state);
306         struct monitor_msg msg;
307         struct msg_rpc_lookup_name *msg_lookup;
308         struct msg_rpc_open_user *msg_open;
309         
310         switch (s->stage) {
311         case USERDEL_LOOKUP:
312                 c->status = userdel_lookup(c, s);
313
314                 msg.type = rpc_lookup_name;
315                 msg_lookup = talloc(s, struct msg_rpc_lookup_name);
316                 msg_lookup->rid = s->lookupname.out.rids.ids;
317                 msg_lookup->count = s->lookupname.out.rids.count;
318                 msg.data = (void*)msg_lookup;
319                 msg.data_size = sizeof(*msg_lookup);
320                 break;
321
322         case USERDEL_OPEN:
323                 c->status = userdel_open(c, s);
324
325                 msg.type = rpc_open_user;
326                 msg_open = talloc(s, struct msg_rpc_open_user);
327                 msg_open->rid = s->openuser.in.rid;
328                 msg_open->access_mask = s->openuser.in.rid;
329                 msg.data = (void*)msg_open;
330                 msg.data_size = sizeof(*msg_open);
331                 break;
332
333         case USERDEL_DELETE:
334                 c->status = userdel_delete(c, s);
335                 
336                 msg.type = rpc_delete_user;
337                 msg.data = NULL;
338                 msg.data_size = 0;
339                 break;
340         }
341
342         if (!NT_STATUS_IS_OK(c->status)) {
343                 c->state = SMBCLI_REQUEST_ERROR;
344         }
345
346         if (c->monitor_fn) {
347                 c->monitor_fn(&msg);
348         }
349
350         if (c->state >= SMBCLI_REQUEST_DONE &&
351             c->async.fn) {
352                 c->async.fn(c);
353         }
354 }
355
356
357 /**
358  * Sends asynchronous userdel request
359  *
360  * @param p dce/rpc call pipe
361  * @param io arguments and results of the call
362  */
363
364 struct composite_context *libnet_rpc_userdel_send(struct dcerpc_pipe *p,
365                                                   struct libnet_rpc_userdel *io)
366 {
367         struct composite_context *c;
368         struct userdel_state *s;
369         
370         c = talloc_zero(p, struct composite_context);
371         if (c == NULL) goto failure;
372
373         s = talloc_zero(c, struct userdel_state);
374         if (s == NULL) goto failure;
375
376         c->state      = SMBCLI_REQUEST_SEND;
377         c->private    = s;
378         c->event_ctx  = dcerpc_event_context(p);
379
380         s->pipe          = p;
381         s->domain_handle = io->in.domain_handle;
382         
383         /* preparing parameters to send rpc request */
384         s->lookupname.in.domain_handle = &io->in.domain_handle;
385         s->lookupname.in.num_names     = 1;
386         s->lookupname.in.names         = talloc_zero(s, struct lsa_String);
387         s->lookupname.in.names->string = io->in.username;
388
389         /* send the request */
390         s->req = dcerpc_samr_LookupNames_send(p, c, &s->lookupname);
391
392         /* callback handler */
393         s->req->async.callback = userdel_handler;
394         s->req->async.private  = c;
395         s->stage = USERDEL_LOOKUP;
396
397         return c;
398
399 failure:
400         talloc_free(c);
401         return NULL;
402 }
403
404
405 /**
406  * Waits for and receives results of asynchronous userdel call
407  *
408  * @param c composite context returned by asynchronous userdel call
409  * @param mem_ctx memory context of the call
410  * @param io pointer to results (and arguments) of the call
411  * @return nt status code of execution
412  */
413
414 NTSTATUS libnet_rpc_userdel_recv(struct composite_context *c, TALLOC_CTX *mem_ctx,
415                                  struct libnet_rpc_userdel *io)
416 {
417         NTSTATUS status;
418         struct userdel_state *s;
419         
420         status = composite_wait(c);
421
422         if (NT_STATUS_IS_OK(status) && io) {
423                 s  = talloc_get_type(c->private, struct userdel_state);
424                 io->out.user_handle = s->user_handle;
425         }
426
427         talloc_free(c);
428         return status;
429 }
430
431
432 /**
433  * Synchronous version of userdel call
434  *
435  * @param pipe dce/rpc call pipe
436  * @param mem_ctx memory context for the call
437  * @param io arguments and results of the call
438  * @return nt status code of execution
439  */
440
441 NTSTATUS libnet_rpc_userdel(struct dcerpc_pipe *pipe,
442                             TALLOC_CTX *mem_ctx,
443                             struct libnet_rpc_userdel *io)
444 {
445         struct composite_context *c = libnet_rpc_userdel_send(pipe, io);
446         return libnet_rpc_userdel_recv(c, mem_ctx, io);
447 }
448
449
450 static void usermod_handler(struct rpc_request*);
451
452 enum usermod_stage { USERMOD_LOOKUP, USERMOD_OPEN, USERMOD_QUERY, USERMOD_MODIFY };
453
454 struct usermod_state {
455         enum usermod_stage         stage;
456         struct dcerpc_pipe         *pipe;
457         struct rpc_request         *req;
458         struct policy_handle       domain_handle;
459         struct policy_handle       user_handle;
460         struct usermod_change      change;
461         union  samr_UserInfo       info;
462         struct samr_LookupNames    lookupname;
463         struct samr_OpenUser       openuser;
464         struct samr_SetUserInfo    setuser;
465         struct samr_QueryUserInfo  queryuser;
466 };
467
468
469 /**
470  * Step 1: Lookup user name
471  */
472 static NTSTATUS usermod_lookup(struct composite_context *c,
473                                struct usermod_state *s)
474 {
475         NTSTATUS status;
476
477         c->status = dcerpc_ndr_request_recv(s->req);
478         NT_STATUS_NOT_OK_RETURN(c->status);
479
480         if (!s->lookupname.out.rids.count) {
481                 /* TODO: no such user */
482                 status = NT_STATUS_NO_SUCH_USER;
483
484         } else if (!s->lookupname.out.rids.count > 1) {
485                 /* TODO: ambiguous username */
486                 status = NT_STATUS_INVALID_ACCOUNT_NAME;
487         }
488
489         s->openuser.in.domain_handle = &s->domain_handle;
490         s->openuser.in.rid           = s->lookupname.out.rids.ids[0];
491         s->openuser.in.access_mask   = SEC_FLAG_MAXIMUM_ALLOWED;
492         s->openuser.out.user_handle  = &s->user_handle;
493
494         s->req = dcerpc_samr_OpenUser_send(s->pipe, c, &s->openuser);
495
496         s->req->async.callback = usermod_handler;
497         s->req->async.private  = c;
498         s->stage = USERMOD_OPEN;
499         
500         return NT_STATUS_OK;
501 }
502
503
504 static uint32_t usermod_setfields(struct usermod_state *s, uint16_t *level,
505                                   union samr_UserInfo *i)
506 {
507         if (s->change.fields) {
508                 if (s->change.fields & USERMOD_FIELD_ACCOUNT_NAME) {
509                         *level = 7;
510                         i->info7.account_name.string = s->change.account_name;
511
512                         s->change.fields ^= USERMOD_FIELD_ACCOUNT_NAME;
513
514                 } else if (s->change.fields & USERMOD_FIELD_FULL_NAME) {
515                         *level = 8;
516                         i->info8.full_name.string = s->change.full_name;
517                         
518                         s->change.fields ^= USERMOD_FIELD_FULL_NAME;
519
520                 } else if (s->change.fields & USERMOD_FIELD_DESCRIPTION) {
521                         *level = 13;
522                         i->info13.description.string = s->change.description;
523                         
524                         s->change.fields ^= USERMOD_FIELD_DESCRIPTION;
525
526                 } else if (s->change.fields & USERMOD_FIELD_COMMENT) {
527                         *level = 2;
528
529                         if (s->stage == USERMOD_QUERY) {
530                                 /* the user info is obtained, so now set the required field */
531                                 i->info2.comment.string = s->change.comment;
532                                 s->change.fields ^= USERMOD_FIELD_COMMENT;
533
534                         } else {
535                                 /* we need to query the user info before setting one field in it */
536                                 s->stage = USERMOD_QUERY;
537                                 return s->change.fields;
538                         }
539
540                 } else if (s->change.fields & USERMOD_FIELD_ALLOW_PASS_CHG) {
541                         *level = 3;
542                         
543                         if (s->stage == USERMOD_QUERY) {
544                                 i->info3.allow_password_change = timeval_to_nttime(s->change.allow_password_change);
545                                 s->change.fields ^= USERMOD_FIELD_ALLOW_PASS_CHG;
546
547                         } else {
548                                 s->stage = USERMOD_QUERY;
549                                 return s->change.fields;
550                         }
551
552                 } else if (s->change.fields & USERMOD_FIELD_FORCE_PASS_CHG) {
553                         *level = 3;
554
555                         if (s->stage == USERMOD_QUERY) {
556                                 i->info3.force_password_change = timeval_to_nttime(s->change.force_password_change);
557                                 s->change.fields ^= USERMOD_FIELD_FORCE_PASS_CHG;
558
559                         } else {
560                                 s->stage = USERMOD_QUERY;
561                                 return s->change.fields;
562                         }
563
564                 } else if (s->change.fields & USERMOD_FIELD_LOGON_SCRIPT) {
565                         *level = 11;
566                         i->info11.logon_script.string = s->change.logon_script;
567                         
568                         s->change.fields ^= USERMOD_FIELD_LOGON_SCRIPT;
569
570                 } else if (s->change.fields & USERMOD_FIELD_PROFILE_PATH) {
571                         *level = 12;
572                         i->info12.profile_path.string = s->change.profile_path;
573
574                         s->change.fields ^= USERMOD_FIELD_PROFILE_PATH;
575
576                 } else if (s->change.fields & USERMOD_FIELD_ACCT_EXPIRY) {
577                         *level = 17;
578                         i->info17.acct_expiry = timeval_to_nttime(s->change.acct_expiry);
579
580                         s->change.fields ^= USERMOD_FIELD_ACCT_EXPIRY;
581
582                 } else if (s->change.fields & USERMOD_FIELD_ACCT_FLAGS) {
583                         *level = 16;
584                         i->info16.acct_flags = s->change.acct_flags;
585
586                         s->change.fields ^= USERMOD_FIELD_ACCT_FLAGS;
587                 }
588         }
589
590         /* We're going to be back here again soon unless all fields have been set */
591         if (s->change.fields) {
592                 s->stage = USERMOD_OPEN;
593         } else {
594                 s->stage = USERMOD_MODIFY;
595         }
596
597         return s->change.fields;
598 }
599
600
601 /**
602  * Stage 2: Open user account
603  */
604 static NTSTATUS usermod_open(struct composite_context *c,
605                              struct usermod_state *s)
606 {
607         union samr_UserInfo *i = &s->info;
608         uint16_t level;
609
610         c->status = dcerpc_ndr_request_recv(s->req);
611         NT_STATUS_NOT_OK_RETURN(c->status);
612
613         /* Prepare UserInfo level and data based on bitmask field */
614         s->change.fields = usermod_setfields(s, &level, i);
615
616         if (s->stage == USERMOD_QUERY) {
617                 s->queryuser.in.user_handle = &s->user_handle;
618                 s->queryuser.in.level       = level;
619
620                 s->req = dcerpc_samr_QueryUserInfo_send(s->pipe, c, &s->queryuser);
621
622         } else {
623                 s->setuser.in.user_handle  = &s->user_handle;
624                 s->setuser.in.level        = level;
625                 s->setuser.in.info         = i;
626
627                 s->req = dcerpc_samr_SetUserInfo_send(s->pipe, c, &s->setuser);
628         }
629
630         s->req->async.callback = usermod_handler;
631         s->req->async.private  = c;
632
633         return NT_STATUS_OK;
634 }
635
636
637 /**
638  * Stage 2a (optional): Query the user information
639  */
640 static NTSTATUS usermod_query(struct composite_context *c,
641                               struct usermod_state *s)
642 {
643         union samr_UserInfo *i = &s->info;
644         uint16_t level;
645
646         c->status = dcerpc_ndr_request_recv(s->req);
647         NT_STATUS_NOT_OK_RETURN(c->status);
648
649         s->info = *s->queryuser.out.info;
650
651         s->change.fields = usermod_setfields(s, &level, i);
652
653         s->setuser.in.user_handle  = &s->user_handle;
654         s->setuser.in.level        = level;
655         s->setuser.in.info         = i;
656         
657         s->req = dcerpc_samr_SetUserInfo_send(s->pipe, c, &s->setuser);
658
659         s->req->async.callback = usermod_handler;
660         s->req->async.private  = c;
661
662         return NT_STATUS_OK;
663 }
664
665
666 /**
667  * Stage 3: Set new user account data
668  */
669 static NTSTATUS usermod_modify(struct composite_context *c,
670                                struct usermod_state *s)
671 {
672         c->status = dcerpc_ndr_request_recv(s->req);
673         NT_STATUS_NOT_OK_RETURN(c->status);
674
675         c->state = SMBCLI_REQUEST_DONE;
676
677         return NT_STATUS_OK;
678 }
679
680
681 /**
682  * Event handler for asynchronous request. Handles transition through
683  * intermediate stages of the call.
684  *
685  * @param req rpc call context
686  */
687
688 static void usermod_handler(struct rpc_request *req)
689 {
690         struct composite_context *c = req->async.private;
691         struct usermod_state *s = talloc_get_type(c->private, struct usermod_state);
692         struct monitor_msg msg;
693
694         switch (s->stage) {
695         case USERMOD_LOOKUP:
696                 c->status = usermod_lookup(c, s);
697                 break;
698
699         case USERMOD_OPEN:
700                 c->status = usermod_open(c, s);
701                 break;
702
703         case USERMOD_QUERY:
704                 c->status = usermod_query(c, s);
705                 break;
706
707         case USERMOD_MODIFY:
708                 c->status = usermod_modify(c, s);
709                 break;
710         }
711
712         if (!NT_STATUS_IS_OK(c->status)) {
713                 c->state = SMBCLI_REQUEST_ERROR;
714         }
715
716         if (c->monitor_fn) {
717                 c->monitor_fn(&msg);
718         }
719
720         if (c->state >= SMBCLI_REQUEST_DONE &&
721             c->async.fn) {
722                 c->async.fn(c);
723         }
724 }
725
726
727 /**
728  * Sends asynchronous usermod request
729  *
730  * @param p dce/rpc call pipe
731  * @param io arguments and results of the call
732  */
733
734 struct composite_context *libnet_rpc_usermod_send(struct dcerpc_pipe *p,
735                                                   struct libnet_rpc_usermod *io)
736 {
737         struct composite_context *c;
738         struct usermod_state *s;
739         
740         c = talloc_zero(p, struct composite_context);
741         if (c == NULL) goto failure;
742
743         s = talloc_zero(c, struct usermod_state);
744         if (s == NULL) goto failure;
745
746         c->state      = SMBCLI_REQUEST_SEND;
747         c->private    = s;
748         c->event_ctx  = dcerpc_event_context(p);
749
750         s->pipe          = p;
751         s->domain_handle = io->in.domain_handle;
752         s->change        = io->in.change;
753         
754         s->lookupname.in.domain_handle = &io->in.domain_handle;
755         s->lookupname.in.num_names     = 1;
756         s->lookupname.in.names         = talloc_zero(s, struct lsa_String);
757         s->lookupname.in.names->string = io->in.username;
758         
759         s->req = dcerpc_samr_LookupNames_send(p, c, &s->lookupname);
760         
761         s->req->async.callback = usermod_handler;
762         s->req->async.private  = c;
763         s->stage = USERMOD_LOOKUP;
764
765         return c;
766
767 failure:
768         talloc_free(c);
769         return NULL;
770 }
771
772
773 /**
774  * Waits for and receives results of asynchronous usermod call
775  *
776  * @param c composite context returned by asynchronous usermod call
777  * @param mem_ctx memory context of the call
778  * @param io pointer to results (and arguments) of the call
779  * @return nt status code of execution
780  */
781
782 NTSTATUS libnet_rpc_usermod_recv(struct composite_context *c, TALLOC_CTX *mem_ctx,
783                                  struct libnet_rpc_usermod *io)
784 {
785         NTSTATUS status;
786         
787         status = composite_wait(c);
788
789         talloc_free(c);
790         return status;
791 }
792
793
794 /**
795  * Synchronous version of usermod call
796  *
797  * @param pipe dce/rpc call pipe
798  * @param mem_ctx memory context for the call
799  * @param io arguments and results of the call
800  * @return nt status code of execution
801  */
802
803 NTSTATUS libnet_rpc_usermod(struct dcerpc_pipe *pipe,
804                             TALLOC_CTX *mem_ctx,
805                             struct libnet_rpc_usermod *io)
806 {
807         struct composite_context *c = libnet_rpc_usermod_send(pipe, io);
808         return libnet_rpc_usermod_recv(c, mem_ctx, io);
809 }