1 /*add's a user to a domain*/
5 int main(int argc
, char **argv
) {
6 CacServerHandle
*hnd
= NULL
;
7 TALLOC_CTX
*mem_ctx
= NULL
;
11 struct SamOpenUser ou
;
13 POLICY_HND
*user_hnd
= NULL
;
15 mem_ctx
= talloc_init("cac_adduser");
17 hnd
= cac_NewServerHandle(True
);
19 cac_SetAuthDataFn(hnd
, cactest_GetAuthDataFn
);
21 cac_parse_cmd_line(argc
, argv
, hnd
);
23 if(!cac_Connect(hnd
, NULL
)) {
24 fprintf(stderr
, "Could not connect to server %s. Error: %s\n", hnd
->server
, nt_errstr(hnd
->status
));
28 struct SamOpenDomain sod
;
31 sod
.in
.access
= MAXIMUM_ALLOWED_ACCESS
;
33 if(!cac_SamOpenDomain(hnd
, mem_ctx
, &sod
)) {
34 fprintf(stderr
, "Could not open domain. Error: %s\n", nt_errstr(hnd
->status
));
38 struct SamCreateUser cdu
;
41 printf("Enter account name: ");
42 cactest_readline(stdin
, tmp
);
44 cdu
.in
.dom_hnd
= sod
.out
.dom_hnd
;
45 cdu
.in
.name
= talloc_strdup(mem_ctx
, tmp
);
46 cdu
.in
.acb_mask
= ACB_NORMAL
;
48 if(!cac_SamCreateUser(hnd
, mem_ctx
, &cdu
)) {
49 fprintf(stderr
, "Could not create user %s. Error: %s\n", cdu
.in
.name
, nt_errstr(hnd
->status
));
52 printf("would you like to delete this user? [y/n]: ");
53 cactest_readline(stdin
, tmp
);
57 if(!cdu
.out
.user_hnd
) {
59 ou
.in
.dom_hnd
= sod
.out
.dom_hnd
;
60 ou
.in
.access
= MAXIMUM_ALLOWED_ACCESS
;
61 ou
.in
.name
= talloc_strdup(mem_ctx
, cdu
.in
.name
);
63 if(!cac_SamOpenUser(hnd
, mem_ctx
, &ou
)) {
64 fprintf(stderr
, "Could not open user for deletion. Error: %s\n", nt_errstr(hnd
->status
));
67 user_hnd
= ou
.out
.user_hnd
;
71 user_hnd
= cdu
.out
.user_hnd
;
74 if(!cac_SamDeleteUser(hnd
, mem_ctx
, user_hnd
))
75 fprintf(stderr
, "Could not delete user. Error: %s\n", nt_errstr(hnd
->status
));
81 cac_SamClose(hnd
, mem_ctx
, sod
.out
.dom_hnd
);
82 cac_SamClose(hnd
, mem_ctx
, sod
.out
.sam
);
85 talloc_destroy(mem_ctx
);
92 /*TODO: add a function that will create a user and set userinfo and set the password*/