00001
00002 #include "libmsrpc.h"
00003 #include "test_util.h"
00004
00005 int main(int argc, char **argv) {
00006 CacServerHandle *hnd = NULL;
00007 TALLOC_CTX *mem_ctx = NULL;
00008
00009 fstring tmp;
00010
00011 struct SamOpenUser ou;
00012
00013 POLICY_HND *user_hnd = NULL;
00014
00015 mem_ctx = talloc_init("cac_adduser");
00016
00017 hnd = cac_NewServerHandle(True);
00018
00019 cac_SetAuthDataFn(hnd, cactest_GetAuthDataFn);
00020
00021 cac_parse_cmd_line(argc, argv, hnd);
00022
00023 if(!cac_Connect(hnd, NULL)) {
00024 fprintf(stderr, "Could not connect to server %s. Error: %s\n", hnd->server, nt_errstr(hnd->status));
00025 exit(-1);
00026 }
00027
00028 struct SamOpenDomain sod;
00029 ZERO_STRUCT(sod);
00030
00031 sod.in.access = MAXIMUM_ALLOWED_ACCESS;
00032
00033 if(!cac_SamOpenDomain(hnd, mem_ctx, &sod)) {
00034 fprintf(stderr, "Could not open domain. Error: %s\n", nt_errstr(hnd->status));
00035 goto done;
00036 }
00037
00038 struct SamCreateUser cdu;
00039 ZERO_STRUCT(cdu);
00040
00041 printf("Enter account name: ");
00042 cactest_readline(stdin, tmp);
00043
00044 cdu.in.dom_hnd = sod.out.dom_hnd;
00045 cdu.in.name = talloc_strdup(mem_ctx, tmp);
00046 cdu.in.acb_mask = ACB_NORMAL;
00047
00048 if(!cac_SamCreateUser(hnd, mem_ctx, &cdu)) {
00049 fprintf(stderr, "Could not create user %s. Error: %s\n", cdu.in.name, nt_errstr(hnd->status));
00050 }
00051
00052 printf("would you like to delete this user? [y/n]: ");
00053 cactest_readline(stdin, tmp);
00054
00055 if(tmp[0] == 'y') {
00056
00057 if(!cdu.out.user_hnd) {
00058 ZERO_STRUCT(ou);
00059 ou.in.dom_hnd = sod.out.dom_hnd;
00060 ou.in.access = MAXIMUM_ALLOWED_ACCESS;
00061 ou.in.name = talloc_strdup(mem_ctx, cdu.in.name);
00062
00063 if(!cac_SamOpenUser(hnd, mem_ctx, &ou)) {
00064 fprintf(stderr, "Could not open user for deletion. Error: %s\n", nt_errstr(hnd->status));
00065 }
00066
00067 user_hnd = ou.out.user_hnd;
00068 }
00069
00070 else {
00071 user_hnd = cdu.out.user_hnd;
00072 }
00073
00074 if(!cac_SamDeleteUser(hnd, mem_ctx, user_hnd))
00075 fprintf(stderr, "Could not delete user. Error: %s\n", nt_errstr(hnd->status));
00076 }
00077 else {
00078 printf("Nope..ok\n");
00079 }
00080
00081 cac_SamClose(hnd, mem_ctx, sod.out.dom_hnd);
00082 cac_SamClose(hnd, mem_ctx, sod.out.sam);
00083
00084 done:
00085 talloc_destroy(mem_ctx);
00086
00087 cac_FreeHandle(hnd);
00088
00089 return 0;
00090 }
00091
00092