1/*add's a user to a domain*/ 2#include "libmsrpc.h" 3#include "test_util.h" 4 5int main(int argc, char **argv) { 6 CacServerHandle *hnd = NULL; 7 TALLOC_CTX *mem_ctx = NULL; 8 9 fstring tmp; 10 11 struct SamOpenUser ou; 12 13 POLICY_HND *user_hnd = NULL; 14 15 mem_ctx = talloc_init("cac_adduser"); 16 17 hnd = cac_NewServerHandle(True); 18 19 cac_SetAuthDataFn(hnd, cactest_GetAuthDataFn); 20 21 cac_parse_cmd_line(argc, argv, hnd); 22 23 if(!cac_Connect(hnd, NULL)) { 24 fprintf(stderr, "Could not connect to server %s. Error: %s\n", hnd->server, nt_errstr(hnd->status)); 25 exit(-1); 26 } 27 28 struct SamOpenDomain sod; 29 ZERO_STRUCT(sod); 30 31 sod.in.access = MAXIMUM_ALLOWED_ACCESS; 32 33 if(!cac_SamOpenDomain(hnd, mem_ctx, &sod)) { 34 fprintf(stderr, "Could not open domain. Error: %s\n", nt_errstr(hnd->status)); 35 goto done; 36 } 37 38 struct SamCreateUser cdu; 39 ZERO_STRUCT(cdu); 40 41 printf("Enter account name: "); 42 cactest_readline(stdin, tmp); 43 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; 47 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)); 50 } 51 52 printf("would you like to delete this user? [y/n]: "); 53 cactest_readline(stdin, tmp); 54 55 if(tmp[0] == 'y') { 56 57 if(!cdu.out.user_hnd) { 58 ZERO_STRUCT(ou); 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); 62 63 if(!cac_SamOpenUser(hnd, mem_ctx, &ou)) { 64 fprintf(stderr, "Could not open user for deletion. Error: %s\n", nt_errstr(hnd->status)); 65 } 66 67 user_hnd = ou.out.user_hnd; 68 } 69 70 else { 71 user_hnd = cdu.out.user_hnd; 72 } 73 74 if(!cac_SamDeleteUser(hnd, mem_ctx, user_hnd)) 75 fprintf(stderr, "Could not delete user. Error: %s\n", nt_errstr(hnd->status)); 76 } 77 else { 78 printf("Nope..ok\n"); 79 } 80 81 cac_SamClose(hnd, mem_ctx, sod.out.dom_hnd); 82 cac_SamClose(hnd, mem_ctx, sod.out.sam); 83 84done: 85 talloc_destroy(mem_ctx); 86 87 cac_FreeHandle(hnd); 88 89 return 0; 90} 91 92/*TODO: add a function that will create a user and set userinfo and set the password*/ 93