summaryrefslogtreecommitdiff
path: root/examples/libmsrpc/test/sam/samlookup.c
diff options
context:
space:
mode:
authorGerald Carter <jerry@samba.org>2005-09-03 16:55:45 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 11:03:30 -0500
commit3c6b0f965588aab0edbc4d115fb9e72c884ded3b (patch)
treece3740784555e729297955c924e4701feaf69d38 /examples/libmsrpc/test/sam/samlookup.c
parenta44e97c99f61916db3f7cc02cd2581c8d64be73a (diff)
downloadsamba-3c6b0f965588aab0edbc4d115fb9e72c884ded3b.tar.gz
samba-3c6b0f965588aab0edbc4d115fb9e72c884ded3b.tar.bz2
samba-3c6b0f965588aab0edbc4d115fb9e72c884ded3b.zip
r10003: in the rush for 10k, I forgot to run add the rest of Chris' libmsrpc files
(This used to be commit 32bebc452dffa8348b94c5b866350b1fe761986f)
Diffstat (limited to 'examples/libmsrpc/test/sam/samlookup.c')
-rw-r--r--examples/libmsrpc/test/sam/samlookup.c140
1 files changed, 140 insertions, 0 deletions
diff --git a/examples/libmsrpc/test/sam/samlookup.c b/examples/libmsrpc/test/sam/samlookup.c
new file mode 100644
index 0000000000..32be50d4b9
--- /dev/null
+++ b/examples/libmsrpc/test/sam/samlookup.c
@@ -0,0 +1,140 @@
+/*lookup names or rids*/
+
+#include "libmsrpc.h"
+#include "test_util.h"
+
+int main(int argc, char **argv) {
+ CacServerHandle *hnd = NULL;
+ TALLOC_CTX *mem_ctx = NULL;
+
+
+ struct SamGetNamesFromRids sgn;
+ struct SamGetRidsFromNames sgr;
+
+ fstring tmp;
+ fstring input;
+
+ int i;
+
+ mem_ctx = talloc_init("cac_samenum");
+
+ hnd = cac_NewServerHandle(True);
+
+ cac_parse_cmd_line(argc, argv, hnd);
+
+ if(!cac_Connect(hnd, NULL)) {
+ fprintf(stderr, "Could not connect to server %s. Error: %s\n", hnd->server, nt_errstr(hnd->status));
+ exit(-1);
+ }
+
+ struct SamOpenDomain sod;
+ ZERO_STRUCT(sod);
+
+ sod.in.access = MAXIMUM_ALLOWED_ACCESS;
+
+ if(!cac_SamOpenDomain(hnd, mem_ctx, &sod)) {
+ fprintf(stderr, "Could not open domain. Error: %s\n", nt_errstr(hnd->status));
+ goto done;
+ }
+
+ tmp[0] = 0x00;
+ while(tmp[0] != 'q') {
+ printf("get [n]ames or get [r]ids or [q]uit: ");
+ cactest_readline(stdin, tmp);
+
+ switch(tmp[0]) {
+ case 'n':
+ ZERO_STRUCT(sgn);
+
+ sgn.in.dom_hnd = sod.out.dom_hnd;
+
+ printf("How many rids will you enter: ");
+ scanf("%d", &sgn.in.num_rids);
+
+ sgn.in.rids = talloc_array(mem_ctx, int, sgn.in.num_rids);
+
+ for(i = 0; i < sgn.in.num_rids; i++) {
+ printf(" Enter RID %d: 0x", i);
+ scanf("%x", &sgn.in.rids[i]);
+ }
+
+ printf("Getting names...\n");
+
+ if(!cac_SamGetNamesFromRids(hnd, mem_ctx, &sgn)) {
+ fprintf(stderr, "could not lookup names. Error: %s\n", nt_errstr(hnd->status));
+ talloc_free(sgn.in.rids);
+ continue;
+ }
+
+ printf("Found %d names:\n", sgn.out.num_names);
+
+ for(i = 0; i < sgn.out.num_names; i++) {
+ printf(" RID: 0x%x ", sgn.out.map[i].rid);
+
+ if(sgn.out.map[i].found) {
+ printf("Name: %s\n", sgn.out.map[i].name);
+ }
+ else {
+ printf("Unknown RID\n");
+ }
+
+ }
+
+ break;
+
+ case 'r':
+ ZERO_STRUCT(sgr);
+
+ sgr.in.dom_hnd = sod.out.dom_hnd;
+
+ printf("How many names will you enter: ");
+ scanf("%d", &sgr.in.num_names);
+
+ sgr.in.names = talloc_array(mem_ctx, char *, sgr.in.num_names);
+
+ for(i = 0; i < sgr.in.num_names; i++) {
+ printf(" Enter name %d: ", (i+1));
+ cactest_readline(stdin, input);
+
+ sgr.in.names[i] = talloc_strdup(mem_ctx, input);
+ }
+
+ if(!cac_SamGetRidsFromNames(hnd, mem_ctx, &sgr)) {
+ fprintf(stderr, "Could not lookup names. Error: %s\n", nt_errstr(hnd->status));
+ continue;
+ }
+
+ printf("Found %d RIDs:\n", sgr.out.num_rids);
+
+ for(i = 0; i < sgr.out.num_rids; i++) {
+ printf(" Name: %s ", sgr.out.map[i].name);
+
+ if(sgr.out.map[i].found) {
+ printf("RID: 0x%x\n", sgr.out.map[i].rid);
+ }
+ else {
+ printf("Unknown name\n");
+ }
+ }
+
+ break;
+ case 'q':
+ printf("\n");
+ break;
+ default:
+ printf("Invalid command!\n");
+ }
+ }
+
+
+ cac_SamClose(hnd, mem_ctx, sod.out.dom_hnd);
+ cac_SamClose(hnd, mem_ctx, sod.out.sam);
+
+done:
+ talloc_destroy(mem_ctx);
+ cac_FreeHandle(hnd);
+
+ return 0;
+
+}
+