#include "libmsrpc.h"#include "test_util.h"Go to the source code of this file.
Functions | |
| int | main (int argc, char **argv) |
|
||||||||||||
|
Definition at line 6 of file samlookup.c. References cac_Connect(), cac_FreeHandle(), cac_NewServerHandle(), cac_parse_cmd_line(), cac_SamClose(), cac_SamGetNamesFromRids(), cac_SamGetRidsFromNames(), cac_SamOpenDomain(), cactest_readline(), fprintf(), SamGetRidsFromNames::in, SamGetNamesFromRids::in, SamOpenDomain::in, MAXIMUM_ALLOWED_ACCESS, nt_errstr(), SamGetRidsFromNames::out, SamGetNamesFromRids::out, SamOpenDomain::out, printf(), _CACSERVERHANDLE::server, _CACSERVERHANDLE::status, talloc_array, talloc_destroy, talloc_free(), talloc_init(), talloc_strdup(), True, and ZERO_STRUCT. 00006 { 00007 CacServerHandle *hnd = NULL; 00008 TALLOC_CTX *mem_ctx = NULL; 00009 00010 00011 struct SamGetNamesFromRids sgn; 00012 struct SamGetRidsFromNames sgr; 00013 00014 fstring tmp; 00015 fstring input; 00016 00017 int i; 00018 00019 mem_ctx = talloc_init("cac_samenum"); 00020 00021 hnd = cac_NewServerHandle(True); 00022 00023 cac_parse_cmd_line(argc, argv, hnd); 00024 00025 if(!cac_Connect(hnd, NULL)) { 00026 fprintf(stderr, "Could not connect to server %s. Error: %s\n", hnd->server, nt_errstr(hnd->status)); 00027 exit(-1); 00028 } 00029 00030 struct SamOpenDomain sod; 00031 ZERO_STRUCT(sod); 00032 00033 sod.in.access = MAXIMUM_ALLOWED_ACCESS; 00034 00035 if(!cac_SamOpenDomain(hnd, mem_ctx, &sod)) { 00036 fprintf(stderr, "Could not open domain. Error: %s\n", nt_errstr(hnd->status)); 00037 goto done; 00038 } 00039 00040 tmp[0] = 0x00; 00041 while(tmp[0] != 'q') { 00042 printf("get [n]ames or get [r]ids or [q]uit: "); 00043 cactest_readline(stdin, tmp); 00044 00045 switch(tmp[0]) { 00046 case 'n': 00047 ZERO_STRUCT(sgn); 00048 00049 sgn.in.dom_hnd = sod.out.dom_hnd; 00050 00051 printf("How many rids will you enter: "); 00052 scanf("%d", &sgn.in.num_rids); 00053 00054 sgn.in.rids = talloc_array(mem_ctx, int, sgn.in.num_rids); 00055 00056 for(i = 0; i < sgn.in.num_rids; i++) { 00057 printf(" Enter RID %d: 0x", i); 00058 scanf("%x", &sgn.in.rids[i]); 00059 } 00060 00061 printf("Getting names...\n"); 00062 00063 if(!cac_SamGetNamesFromRids(hnd, mem_ctx, &sgn)) { 00064 fprintf(stderr, "could not lookup names. Error: %s\n", nt_errstr(hnd->status)); 00065 talloc_free(sgn.in.rids); 00066 continue; 00067 } 00068 00069 printf("Found %d names:\n", sgn.out.num_names); 00070 00071 for(i = 0; i < sgn.out.num_names; i++) { 00072 printf(" RID: 0x%x ", sgn.out.map[i].rid); 00073 00074 if(sgn.out.map[i].found) { 00075 printf("Name: %s\n", sgn.out.map[i].name); 00076 } 00077 else { 00078 printf("Unknown RID\n"); 00079 } 00080 00081 } 00082 00083 break; 00084 00085 case 'r': 00086 ZERO_STRUCT(sgr); 00087 00088 sgr.in.dom_hnd = sod.out.dom_hnd; 00089 00090 printf("How many names will you enter: "); 00091 scanf("%d", &sgr.in.num_names); 00092 00093 sgr.in.names = talloc_array(mem_ctx, char *, sgr.in.num_names); 00094 00095 for(i = 0; i < sgr.in.num_names; i++) { 00096 printf(" Enter name %d: ", (i+1)); 00097 cactest_readline(stdin, input); 00098 00099 sgr.in.names[i] = talloc_strdup(mem_ctx, input); 00100 } 00101 00102 if(!cac_SamGetRidsFromNames(hnd, mem_ctx, &sgr)) { 00103 fprintf(stderr, "Could not lookup names. Error: %s\n", nt_errstr(hnd->status)); 00104 continue; 00105 } 00106 00107 printf("Found %d RIDs:\n", sgr.out.num_rids); 00108 00109 for(i = 0; i < sgr.out.num_rids; i++) { 00110 printf(" Name: %s ", sgr.out.map[i].name); 00111 00112 if(sgr.out.map[i].found) { 00113 printf("RID: 0x%x\n", sgr.out.map[i].rid); 00114 } 00115 else { 00116 printf("Unknown name\n"); 00117 } 00118 } 00119 00120 break; 00121 case 'q': 00122 printf("\n"); 00123 break; 00124 default: 00125 printf("Invalid command!\n"); 00126 } 00127 } 00128 00129 00130 cac_SamClose(hnd, mem_ctx, sod.out.dom_hnd); 00131 cac_SamClose(hnd, mem_ctx, sod.out.sam); 00132 00133 done: 00134 talloc_destroy(mem_ctx); 00135 cac_FreeHandle(hnd); 00136 00137 return 0; 00138 00139 }
|