r10504: - seperate implementation specific stuff, from the generic composite
[kai/samba.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/composite/composite.h"
27 #include "librpc/gen_ndr/ndr_samr.h"
28 #include "libnet/composite.h"
29 #include "libnet/userman.h"
30 #include "libnet/userinfo.h"
31
32 /*
33  * Composite user add function
34  */
35
36 static void useradd_handler(struct rpc_request*);
37
38 enum useradd_stage { USERADD_CREATE };
39
40 struct useradd_state {
41         enum useradd_stage       stage;
42         struct dcerpc_pipe       *pipe;
43         struct rpc_request       *req;
44         struct policy_handle     domain_handle;
45         struct samr_CreateUser   createuser;
46         struct policy_handle     user_handle;
47         uint32_t                 user_rid;
48         /* information about the progress */
49         void (*monitor_fn)(struct monitor_msg *);
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 = COMPOSITE_STATE_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_data, 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 = COMPOSITE_STATE_ERROR;
94         }
95
96         if (s->monitor_fn) {
97                 s->monitor_fn(&msg);
98         }
99
100         if (c->state >= COMPOSITE_STATE_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         s->monitor_fn    = monitor;
130         
131         c->state       = COMPOSITE_STATE_IN_PROGRESS;
132         c->private_data= s;
133         c->event_ctx   = dcerpc_event_context(p);
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_data, 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         /* information about the progress */
222         void (*monitor_fn)(struct monitor_msg *);
223 };
224
225
226 /**
227  * Stage 1: Lookup the user name and resolve it to rid
228  */
229 static NTSTATUS userdel_lookup(struct composite_context *c,
230                                struct userdel_state *s)
231 {
232         NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
233
234         c->status = dcerpc_ndr_request_recv(s->req);
235         NT_STATUS_NOT_OK_RETURN(c->status);
236         
237         if (!s->lookupname.out.rids.count) {
238                 /* TODO: no such user */
239                 status = NT_STATUS_NO_SUCH_USER;
240
241         } else if (!s->lookupname.out.rids.count > 1) {
242                 /* TODO: ambiguous username */
243                 status = NT_STATUS_INVALID_ACCOUNT_NAME;
244         }
245         
246         s->openuser.in.domain_handle = &s->domain_handle;
247         s->openuser.in.rid           = s->lookupname.out.rids.ids[0];
248         s->openuser.in.access_mask   = SEC_FLAG_MAXIMUM_ALLOWED;
249         s->openuser.out.user_handle  = &s->user_handle;
250
251         s->req = dcerpc_samr_OpenUser_send(s->pipe, c, &s->openuser);
252         
253         s->req->async.callback = userdel_handler;
254         s->req->async.private  = c;
255         s->stage = USERDEL_OPEN;
256         
257         return NT_STATUS_OK;
258 }
259
260
261 /**
262  * Stage 2: Open user account.
263  */
264 static NTSTATUS userdel_open(struct composite_context *c,
265                              struct userdel_state *s)
266 {
267         c->status = dcerpc_ndr_request_recv(s->req);
268         NT_STATUS_NOT_OK_RETURN(c->status);
269         
270         s->deleteuser.in.user_handle   = &s->user_handle;
271         s->deleteuser.out.user_handle  = &s->user_handle;
272         
273         s->req = dcerpc_samr_DeleteUser_send(s->pipe, c, &s->deleteuser);
274         
275         s->req->async.callback = userdel_handler;
276         s->req->async.private  = c;
277         s->stage = USERDEL_DELETE;
278         
279         return NT_STATUS_OK;
280 }
281
282
283 /**
284  * Stage 3: Delete user account
285  */
286 static NTSTATUS userdel_delete(struct composite_context *c,
287                                struct userdel_state *s)
288 {
289         c->status = dcerpc_ndr_request_recv(s->req);
290         NT_STATUS_NOT_OK_RETURN(c->status);
291         
292         c->state = COMPOSITE_STATE_DONE;
293
294         return NT_STATUS_OK;
295 }
296
297
298 /**
299  * Event handler for asynchronous request. Handles transition through
300  * intermediate stages of the call.
301  *
302  * @param req rpc call context
303  */
304 static void userdel_handler(struct rpc_request *req)
305 {
306         struct composite_context *c = req->async.private;
307         struct userdel_state *s = talloc_get_type(c->private_data, struct userdel_state);
308         struct monitor_msg msg;
309         struct msg_rpc_lookup_name *msg_lookup;
310         struct msg_rpc_open_user *msg_open;
311         
312         switch (s->stage) {
313         case USERDEL_LOOKUP:
314                 c->status = userdel_lookup(c, s);
315
316                 msg.type = rpc_lookup_name;
317                 msg_lookup = talloc(s, struct msg_rpc_lookup_name);
318                 msg_lookup->rid = s->lookupname.out.rids.ids;
319                 msg_lookup->count = s->lookupname.out.rids.count;
320                 msg.data = (void*)msg_lookup;
321                 msg.data_size = sizeof(*msg_lookup);
322                 break;
323
324         case USERDEL_OPEN:
325                 c->status = userdel_open(c, s);
326
327                 msg.type = rpc_open_user;
328                 msg_open = talloc(s, struct msg_rpc_open_user);
329                 msg_open->rid = s->openuser.in.rid;
330                 msg_open->access_mask = s->openuser.in.rid;
331                 msg.data = (void*)msg_open;
332                 msg.data_size = sizeof(*msg_open);
333                 break;
334
335         case USERDEL_DELETE:
336                 c->status = userdel_delete(c, s);
337                 
338                 msg.type = rpc_delete_user;
339                 msg.data = NULL;
340                 msg.data_size = 0;
341                 break;
342         }
343
344         if (!NT_STATUS_IS_OK(c->status)) {
345                 c->state = COMPOSITE_STATE_ERROR;
346         }
347
348         if (s->monitor_fn) {
349                 s->monitor_fn(&msg);
350         }
351
352         if (c->state >= COMPOSITE_STATE_DONE &&
353             c->async.fn) {
354                 c->async.fn(c);
355         }
356 }
357
358
359 /**
360  * Sends asynchronous userdel request
361  *
362  * @param p dce/rpc call pipe
363  * @param io arguments and results of the call
364  */
365
366 struct composite_context *libnet_rpc_userdel_send(struct dcerpc_pipe *p,
367                                                   struct libnet_rpc_userdel *io)
368 {
369         struct composite_context *c;
370         struct userdel_state *s;
371         
372         c = talloc_zero(p, struct composite_context);
373         if (c == NULL) goto failure;
374
375         s = talloc_zero(c, struct userdel_state);
376         if (s == NULL) goto failure;
377
378         c->state       = COMPOSITE_STATE_IN_PROGRESS;
379         c->private_data= s;
380         c->event_ctx   = dcerpc_event_context(p);
381
382         s->pipe          = p;
383         s->domain_handle = io->in.domain_handle;
384         
385         /* preparing parameters to send rpc request */
386         s->lookupname.in.domain_handle = &io->in.domain_handle;
387         s->lookupname.in.num_names     = 1;
388         s->lookupname.in.names         = talloc_zero(s, struct lsa_String);
389         s->lookupname.in.names->string = io->in.username;
390
391         /* send the request */
392         s->req = dcerpc_samr_LookupNames_send(p, c, &s->lookupname);
393
394         /* callback handler */
395         s->req->async.callback = userdel_handler;
396         s->req->async.private  = c;
397         s->stage = USERDEL_LOOKUP;
398
399         return c;
400
401 failure:
402         talloc_free(c);
403         return NULL;
404 }
405
406
407 /**
408 1 * Waits for and receives results of asynchronous userdel call
409  *
410  * @param c composite context returned by asynchronous userdel call
411  * @param mem_ctx memory context of the call
412  * @param io pointer to results (and arguments) of the call
413  * @return nt status code of execution
414  */
415
416 NTSTATUS libnet_rpc_userdel_recv(struct composite_context *c, TALLOC_CTX *mem_ctx,
417                                  struct libnet_rpc_userdel *io)
418 {
419         NTSTATUS status;
420         struct userdel_state *s;
421         
422         status = composite_wait(c);
423
424         if (NT_STATUS_IS_OK(status) && io) {
425                 s  = talloc_get_type(c->private_data, struct userdel_state);
426                 io->out.user_handle = s->user_handle;
427         }
428
429         talloc_free(c);
430         return status;
431 }
432
433
434 /**
435  * Synchronous version of userdel call
436  *
437  * @param pipe dce/rpc call pipe
438  * @param mem_ctx memory context for the call
439  * @param io arguments and results of the call
440  * @return nt status code of execution
441  */
442
443 NTSTATUS libnet_rpc_userdel(struct dcerpc_pipe *pipe,
444                             TALLOC_CTX *mem_ctx,
445                             struct libnet_rpc_userdel *io)
446 {
447         struct composite_context *c = libnet_rpc_userdel_send(pipe, io);
448         return libnet_rpc_userdel_recv(c, mem_ctx, io);
449 }
450
451
452 static void usermod_handler(struct rpc_request*);
453
454 enum usermod_stage { USERMOD_LOOKUP, USERMOD_OPEN, USERMOD_QUERY, USERMOD_MODIFY };
455
456 struct usermod_state {
457         enum usermod_stage         stage;
458         struct dcerpc_pipe         *pipe;
459         struct rpc_request         *req;
460         struct policy_handle       domain_handle;
461         struct policy_handle       user_handle;
462         struct usermod_change      change;
463         union  samr_UserInfo       info;
464         struct samr_LookupNames    lookupname;
465         struct samr_OpenUser       openuser;
466         struct samr_SetUserInfo    setuser;
467         struct samr_QueryUserInfo  queryuser;
468 };
469
470
471 /**
472  * Step 1: Lookup user name
473  */
474 static NTSTATUS usermod_lookup(struct composite_context *c,
475                                struct usermod_state *s)
476 {
477         NTSTATUS status;
478
479         c->status = dcerpc_ndr_request_recv(s->req);
480         NT_STATUS_NOT_OK_RETURN(c->status);
481
482         if (!s->lookupname.out.rids.count) {
483                 /* TODO: no such user */
484                 status = NT_STATUS_NO_SUCH_USER;
485
486         } else if (!s->lookupname.out.rids.count > 1) {
487                 /* TODO: ambiguous username */
488                 status = NT_STATUS_INVALID_ACCOUNT_NAME;
489         }
490
491         s->openuser.in.domain_handle = &s->domain_handle;
492         s->openuser.in.rid           = s->lookupname.out.rids.ids[0];
493         s->openuser.in.access_mask   = SEC_FLAG_MAXIMUM_ALLOWED;
494         s->openuser.out.user_handle  = &s->user_handle;
495
496         s->req = dcerpc_samr_OpenUser_send(s->pipe, c, &s->openuser);
497
498         s->req->async.callback = usermod_handler;
499         s->req->async.private  = c;
500         s->stage = USERMOD_OPEN;
501         
502         return NT_STATUS_OK;
503 }
504
505
506 static uint32_t usermod_setfields(struct usermod_state *s, uint16_t *level,
507                                   union samr_UserInfo *i)
508 {
509         if (s->change.fields) {
510                 if (s->change.fields & USERMOD_FIELD_ACCOUNT_NAME) {
511                         *level = 7;
512                         i->info7.account_name.string = s->change.account_name;
513
514                         s->change.fields ^= USERMOD_FIELD_ACCOUNT_NAME;
515
516                 } else if (s->change.fields & USERMOD_FIELD_FULL_NAME) {
517                         *level = 8;
518                         i->info8.full_name.string = s->change.full_name;
519                         
520                         s->change.fields ^= USERMOD_FIELD_FULL_NAME;
521
522                 } else if (s->change.fields & USERMOD_FIELD_DESCRIPTION) {
523                         *level = 13;
524                         i->info13.description.string = s->change.description;
525                         
526                         s->change.fields ^= USERMOD_FIELD_DESCRIPTION;
527
528                 } else if (s->change.fields & USERMOD_FIELD_COMMENT) {
529                         *level = 2;
530
531                         if (s->stage == USERMOD_QUERY) {
532                                 /* the user info is obtained, so now set the required field */
533                                 i->info2.comment.string = s->change.comment;
534                                 s->change.fields ^= USERMOD_FIELD_COMMENT;
535
536                         } else {
537                                 /* we need to query the user info before setting one field in it */
538                                 s->stage = USERMOD_QUERY;
539                                 return s->change.fields;
540                         }
541
542                 } else if (s->change.fields & USERMOD_FIELD_ALLOW_PASS_CHG) {
543                         *level = 3;
544                         
545                         if (s->stage == USERMOD_QUERY) {
546                                 i->info3.allow_password_change = timeval_to_nttime(s->change.allow_password_change);
547                                 s->change.fields ^= USERMOD_FIELD_ALLOW_PASS_CHG;
548
549                         } else {
550                                 s->stage = USERMOD_QUERY;
551                                 return s->change.fields;
552                         }
553
554                 } else if (s->change.fields & USERMOD_FIELD_FORCE_PASS_CHG) {
555                         *level = 3;
556
557                         if (s->stage == USERMOD_QUERY) {
558                                 i->info3.force_password_change = timeval_to_nttime(s->change.force_password_change);
559                                 s->change.fields ^= USERMOD_FIELD_FORCE_PASS_CHG;
560
561                         } else {
562                                 s->stage = USERMOD_QUERY;
563                                 return s->change.fields;
564                         }
565
566                 } else if (s->change.fields & USERMOD_FIELD_LOGON_SCRIPT) {
567                         *level = 11;
568                         i->info11.logon_script.string = s->change.logon_script;
569                         
570                         s->change.fields ^= USERMOD_FIELD_LOGON_SCRIPT;
571
572                 } else if (s->change.fields & USERMOD_FIELD_PROFILE_PATH) {
573                         *level = 12;
574                         i->info12.profile_path.string = s->change.profile_path;
575
576                         s->change.fields ^= USERMOD_FIELD_PROFILE_PATH;
577
578                 } else if (s->change.fields & USERMOD_FIELD_ACCT_EXPIRY) {
579                         *level = 17;
580                         i->info17.acct_expiry = timeval_to_nttime(s->change.acct_expiry);
581
582                         s->change.fields ^= USERMOD_FIELD_ACCT_EXPIRY;
583
584                 } else if (s->change.fields & USERMOD_FIELD_ACCT_FLAGS) {
585                         *level = 16;
586                         i->info16.acct_flags = s->change.acct_flags;
587
588                         s->change.fields ^= USERMOD_FIELD_ACCT_FLAGS;
589                 }
590         }
591
592         /* We're going to be back here again soon unless all fields have been set */
593         if (s->change.fields) {
594                 s->stage = USERMOD_OPEN;
595         } else {
596                 s->stage = USERMOD_MODIFY;
597         }
598
599         return s->change.fields;
600 }
601
602
603 /**
604  * Stage 2: Open user account
605  */
606 static NTSTATUS usermod_open(struct composite_context *c,
607                              struct usermod_state *s)
608 {
609         union samr_UserInfo *i = &s->info;
610         uint16_t level;
611
612         c->status = dcerpc_ndr_request_recv(s->req);
613         NT_STATUS_NOT_OK_RETURN(c->status);
614
615         /* Prepare UserInfo level and data based on bitmask field */
616         s->change.fields = usermod_setfields(s, &level, i);
617
618         if (s->stage == USERMOD_QUERY) {
619                 s->queryuser.in.user_handle = &s->user_handle;
620                 s->queryuser.in.level       = level;
621
622                 s->req = dcerpc_samr_QueryUserInfo_send(s->pipe, c, &s->queryuser);
623
624         } else {
625                 s->setuser.in.user_handle  = &s->user_handle;
626                 s->setuser.in.level        = level;
627                 s->setuser.in.info         = i;
628
629                 s->req = dcerpc_samr_SetUserInfo_send(s->pipe, c, &s->setuser);
630         }
631
632         s->req->async.callback = usermod_handler;
633         s->req->async.private  = c;
634
635         return NT_STATUS_OK;
636 }
637
638
639 /**
640  * Stage 2a (optional): Query the user information
641  */
642 static NTSTATUS usermod_query(struct composite_context *c,
643                               struct usermod_state *s)
644 {
645         union samr_UserInfo *i = &s->info;
646         uint16_t level;
647
648         c->status = dcerpc_ndr_request_recv(s->req);
649         NT_STATUS_NOT_OK_RETURN(c->status);
650
651         s->info = *s->queryuser.out.info;
652
653         s->change.fields = usermod_setfields(s, &level, i);
654
655         s->setuser.in.user_handle  = &s->user_handle;
656         s->setuser.in.level        = level;
657         s->setuser.in.info         = i;
658         
659         s->req = dcerpc_samr_SetUserInfo_send(s->pipe, c, &s->setuser);
660
661         s->req->async.callback = usermod_handler;
662         s->req->async.private  = c;
663
664         return NT_STATUS_OK;
665 }
666
667
668 /**
669  * Stage 3: Set new user account data
670  */
671 static NTSTATUS usermod_modify(struct composite_context *c,
672                                struct usermod_state *s)
673 {
674         c->status = dcerpc_ndr_request_recv(s->req);
675         NT_STATUS_NOT_OK_RETURN(c->status);
676
677         c->state = COMPOSITE_STATE_DONE;
678
679         return NT_STATUS_OK;
680 }
681
682
683 /**
684  * Event handler for asynchronous request. Handles transition through
685  * intermediate stages of the call.
686  *
687  * @param req rpc call context
688  */
689
690 static void usermod_handler(struct rpc_request *req)
691 {
692         struct composite_context *c = req->async.private;
693         struct usermod_state *s = talloc_get_type(c->private_data, struct usermod_state);
694
695         switch (s->stage) {
696         case USERMOD_LOOKUP:
697                 c->status = usermod_lookup(c, s);
698                 break;
699
700         case USERMOD_OPEN:
701                 c->status = usermod_open(c, s);
702                 break;
703
704         case USERMOD_QUERY:
705                 c->status = usermod_query(c, s);
706                 break;
707
708         case USERMOD_MODIFY:
709                 c->status = usermod_modify(c, s);
710                 break;
711         }
712
713         if (!NT_STATUS_IS_OK(c->status)) {
714                 c->state = COMPOSITE_STATE_ERROR;
715         }
716
717         if (c->state >= COMPOSITE_STATE_DONE &&
718             c->async.fn) {
719                 c->async.fn(c);
720         }
721 }
722
723
724 /**
725  * Sends asynchronous usermod request
726  *
727  * @param p dce/rpc call pipe
728  * @param io arguments and results of the call
729  */
730
731 struct composite_context *libnet_rpc_usermod_send(struct dcerpc_pipe *p,
732                                                   struct libnet_rpc_usermod *io)
733 {
734         struct composite_context *c;
735         struct usermod_state *s;
736         
737         c = talloc_zero(p, struct composite_context);
738         if (c == NULL) goto failure;
739
740         s = talloc_zero(c, struct usermod_state);
741         if (s == NULL) goto failure;
742
743         c->state        = COMPOSITE_STATE_IN_PROGRESS;
744         c->private_data = s;
745         c->event_ctx    = dcerpc_event_context(p);
746
747         s->pipe          = p;
748         s->domain_handle = io->in.domain_handle;
749         s->change        = io->in.change;
750         
751         s->lookupname.in.domain_handle = &io->in.domain_handle;
752         s->lookupname.in.num_names     = 1;
753         s->lookupname.in.names         = talloc_zero(s, struct lsa_String);
754         s->lookupname.in.names->string = io->in.username;
755         
756         s->req = dcerpc_samr_LookupNames_send(p, c, &s->lookupname);
757         
758         s->req->async.callback = usermod_handler;
759         s->req->async.private  = c;
760         s->stage = USERMOD_LOOKUP;
761
762         return c;
763
764 failure:
765         talloc_free(c);
766         return NULL;
767 }
768
769
770 /**
771  * Waits for and receives results of asynchronous usermod call
772  *
773  * @param c composite context returned by asynchronous usermod call
774  * @param mem_ctx memory context of the call
775  * @param io pointer to results (and arguments) of the call
776  * @return nt status code of execution
777  */
778
779 NTSTATUS libnet_rpc_usermod_recv(struct composite_context *c, TALLOC_CTX *mem_ctx,
780                                  struct libnet_rpc_usermod *io)
781 {
782         NTSTATUS status;
783         
784         status = composite_wait(c);
785
786         talloc_free(c);
787         return status;
788 }
789
790
791 /**
792  * Synchronous version of usermod call
793  *
794  * @param pipe dce/rpc call pipe
795  * @param mem_ctx memory context for the call
796  * @param io arguments and results of the call
797  * @return nt status code of execution
798  */
799
800 NTSTATUS libnet_rpc_usermod(struct dcerpc_pipe *pipe,
801                             TALLOC_CTX *mem_ctx,
802                             struct libnet_rpc_usermod *io)
803 {
804         struct composite_context *c = libnet_rpc_usermod_send(pipe, io);
805         return libnet_rpc_usermod_recv(c, mem_ctx, io);
806 }