Samba 3: added Samba 3.0.24 sources
[tomato.git] / release / src / router / samba3 / examples / libmsrpc / test / sam / samlookup.c
blob32be50d4b925efba0af94b841b32737a0bd4f3d0
1 /*lookup names or rids*/
3 #include "libmsrpc.h"
4 #include "test_util.h"
6 int main(int argc, char **argv) {
7 CacServerHandle *hnd = NULL;
8 TALLOC_CTX *mem_ctx = NULL;
11 struct SamGetNamesFromRids sgn;
12 struct SamGetRidsFromNames sgr;
14 fstring tmp;
15 fstring input;
17 int i;
19 mem_ctx = talloc_init("cac_samenum");
21 hnd = cac_NewServerHandle(True);
23 cac_parse_cmd_line(argc, argv, hnd);
25 if(!cac_Connect(hnd, NULL)) {
26 fprintf(stderr, "Could not connect to server %s. Error: %s\n", hnd->server, nt_errstr(hnd->status));
27 exit(-1);
30 struct SamOpenDomain sod;
31 ZERO_STRUCT(sod);
33 sod.in.access = MAXIMUM_ALLOWED_ACCESS;
35 if(!cac_SamOpenDomain(hnd, mem_ctx, &sod)) {
36 fprintf(stderr, "Could not open domain. Error: %s\n", nt_errstr(hnd->status));
37 goto done;
40 tmp[0] = 0x00;
41 while(tmp[0] != 'q') {
42 printf("get [n]ames or get [r]ids or [q]uit: ");
43 cactest_readline(stdin, tmp);
45 switch(tmp[0]) {
46 case 'n':
47 ZERO_STRUCT(sgn);
49 sgn.in.dom_hnd = sod.out.dom_hnd;
51 printf("How many rids will you enter: ");
52 scanf("%d", &sgn.in.num_rids);
54 sgn.in.rids = talloc_array(mem_ctx, int, sgn.in.num_rids);
56 for(i = 0; i < sgn.in.num_rids; i++) {
57 printf(" Enter RID %d: 0x", i);
58 scanf("%x", &sgn.in.rids[i]);
61 printf("Getting names...\n");
63 if(!cac_SamGetNamesFromRids(hnd, mem_ctx, &sgn)) {
64 fprintf(stderr, "could not lookup names. Error: %s\n", nt_errstr(hnd->status));
65 talloc_free(sgn.in.rids);
66 continue;
69 printf("Found %d names:\n", sgn.out.num_names);
71 for(i = 0; i < sgn.out.num_names; i++) {
72 printf(" RID: 0x%x ", sgn.out.map[i].rid);
74 if(sgn.out.map[i].found) {
75 printf("Name: %s\n", sgn.out.map[i].name);
77 else {
78 printf("Unknown RID\n");
83 break;
85 case 'r':
86 ZERO_STRUCT(sgr);
88 sgr.in.dom_hnd = sod.out.dom_hnd;
90 printf("How many names will you enter: ");
91 scanf("%d", &sgr.in.num_names);
93 sgr.in.names = talloc_array(mem_ctx, char *, sgr.in.num_names);
95 for(i = 0; i < sgr.in.num_names; i++) {
96 printf(" Enter name %d: ", (i+1));
97 cactest_readline(stdin, input);
99 sgr.in.names[i] = talloc_strdup(mem_ctx, input);
102 if(!cac_SamGetRidsFromNames(hnd, mem_ctx, &sgr)) {
103 fprintf(stderr, "Could not lookup names. Error: %s\n", nt_errstr(hnd->status));
104 continue;
107 printf("Found %d RIDs:\n", sgr.out.num_rids);
109 for(i = 0; i < sgr.out.num_rids; i++) {
110 printf(" Name: %s ", sgr.out.map[i].name);
112 if(sgr.out.map[i].found) {
113 printf("RID: 0x%x\n", sgr.out.map[i].rid);
115 else {
116 printf("Unknown name\n");
120 break;
121 case 'q':
122 printf("\n");
123 break;
124 default:
125 printf("Invalid command!\n");
130 cac_SamClose(hnd, mem_ctx, sod.out.dom_hnd);
131 cac_SamClose(hnd, mem_ctx, sod.out.sam);
133 done:
134 talloc_destroy(mem_ctx);
135 cac_FreeHandle(hnd);
137 return 0;