1 /*lookup names or rids*/
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
;
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
));
30 struct SamOpenDomain 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
));
41 while(tmp
[0] != 'q') {
42 printf("get [n]ames or get [r]ids or [q]uit: ");
43 cactest_readline(stdin
, tmp
);
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
);
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
);
78 printf("Unknown RID\n");
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
));
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
);
116 printf("Unknown name\n");
125 printf("Invalid command!\n");
130 cac_SamClose(hnd
, mem_ctx
, sod
.out
.dom_hnd
);
131 cac_SamClose(hnd
, mem_ctx
, sod
.out
.sam
);
134 talloc_destroy(mem_ctx
);