00001
00002
00003 #include "libmsrpc.h"
00004 #include "test_util.h"
00005
00006 int main(int argc, char **argv) {
00007 CacServerHandle *hnd = NULL;
00008 TALLOC_CTX *mem_ctx = NULL;
00009
00010
00011 struct SamEnumUsers eu;
00012 struct SamEnumGroups eg;
00013 struct SamEnumAliases ea;
00014
00015 fstring tmp;
00016
00017 int i;
00018
00019 mem_ctx = talloc_init("cac_samenum");
00020
00021 hnd = cac_NewServerHandle(True);
00022
00023 cac_SetAuthDataFn(hnd, cactest_GetAuthDataFn);
00024
00025 cac_parse_cmd_line(argc, argv, hnd);
00026
00027 if(!cac_Connect(hnd, NULL)) {
00028 fprintf(stderr, "Could not connect to server %s. Error: %s\n", hnd->server, nt_errstr(hnd->status));
00029 exit(-1);
00030 }
00031
00032 struct SamOpenDomain sod;
00033 ZERO_STRUCT(sod);
00034
00035 sod.in.access = MAXIMUM_ALLOWED_ACCESS;
00036
00037 if(!cac_SamOpenDomain(hnd, mem_ctx, &sod)) {
00038 fprintf(stderr, "Could not open domain. Error: %s\n", nt_errstr(hnd->status));
00039 goto done;
00040 }
00041
00042 tmp[0] = 0x00;
00043 while(tmp[0] != 'q') {
00044 printf("Enumerate [u]sers, [g]roups or [a]liases or [q]uit: ");
00045 cactest_readline(stdin, tmp);
00046
00047 switch(tmp[0]) {
00048 case 'u':
00049 ZERO_STRUCT(eu);
00050
00051 eu.in.dom_hnd = sod.out.dom_hnd;
00052
00053 printf("ACB mask (can be 0): ");
00054 scanf("%x", &eu.in.acb_mask);
00055
00056 while(cac_SamEnumUsers(hnd, mem_ctx, &eu)) {
00057 printf("Enumerated %d users:\n", eu.out.num_users);
00058 for(i = 0; i < eu.out.num_users; i++) {
00059 printf(" Name: %s\n", eu.out.names[i]);
00060 printf(" RID: %d\n", eu.out.rids[i]);
00061 }
00062 }
00063
00064 if(CAC_OP_FAILED(hnd->status)) {
00065 printf("Could not enumerate users. Error: %s\n", nt_errstr(hnd->status));
00066 }
00067 break;
00068 case 'g':
00069 ZERO_STRUCT(eg);
00070 eg.in.dom_hnd = sod.out.dom_hnd;
00071
00072 printf("Enumerating groups...\n");
00073 while(cac_SamEnumGroups(hnd, mem_ctx, &eg)) {
00074 printf("Enumerated %d groups:\n", eg.out.num_groups);
00075 for(i = 0; i < eg.out.num_groups; i++) {
00076 printf("RID: %d\n", eg.out.rids[i]);
00077 printf("Name: %s\n", eg.out.names[i]);
00078 printf("Desc: %s\n", eg.out.descriptions[i]);
00079 }
00080 }
00081
00082 if(CAC_OP_FAILED(hnd->status)) {
00083 printf("Could not enumerate Groups. Error: %s\n", nt_errstr(hnd->status));
00084 }
00085 break;
00086 case 'a':
00087 ZERO_STRUCT(ea);
00088 ea.in.dom_hnd = sod.out.dom_hnd;
00089
00090 printf("Enumerating Aliases...\n");
00091 while(cac_SamEnumAliases(hnd, mem_ctx, &ea)) {
00092 printf("Enumerated %d aliases:\n", ea.out.num_aliases);
00093
00094 for(i = 0; i < ea.out.num_aliases; i++) {
00095 printf("RID: %d\n", ea.out.rids[i]);
00096 printf("Name: %s\n", ea.out.names[i]);
00097 printf("Desc: %s\n", ea.out.descriptions[i]);
00098 }
00099 }
00100 if(CAC_OP_FAILED(hnd->status)) {
00101 printf("Could not enumerate Aliases. Error: %s\n", nt_errstr(hnd->status));
00102 }
00103 break;
00104 }
00105 }
00106
00107 cac_SamClose(hnd, mem_ctx, sod.out.dom_hnd);
00108 cac_SamClose(hnd, mem_ctx, sod.out.sam);
00109
00110 done:
00111 talloc_destroy(mem_ctx);
00112 cac_FreeHandle(hnd);
00113
00114 return 0;
00115
00116 }
00117