summaryrefslogtreecommitdiff
path: root/examples/libmsrpc/test/lsa/lsaenum.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/lsa/lsaenum.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/lsa/lsaenum.c')
-rw-r--r--examples/libmsrpc/test/lsa/lsaenum.c96
1 files changed, 96 insertions, 0 deletions
diff --git a/examples/libmsrpc/test/lsa/lsaenum.c b/examples/libmsrpc/test/lsa/lsaenum.c
new file mode 100644
index 0000000000..d4ad4f73aa
--- /dev/null
+++ b/examples/libmsrpc/test/lsa/lsaenum.c
@@ -0,0 +1,96 @@
+/*enumerates SIDs*/
+
+#include "libmsrpc.h"
+#include "includes.h"
+
+int main(int argc, char **argv) {
+
+ CacServerHandle *hnd = NULL;
+ TALLOC_CTX *mem_ctx = NULL;
+
+ POLICY_HND *pol = NULL;
+
+ int i;
+ int max_sids;
+
+ mem_ctx = talloc_init("lsaenum");
+
+ hnd = cac_NewServerHandle(True);
+
+ printf("Enter server to connect to: ");
+ fscanf(stdin, "%s", hnd->server);
+
+ if(!cac_Connect(hnd, NULL)) {
+ fprintf(stderr, "Could not connect to server.\n Error: %s.\n errno: %s\n", nt_errstr(hnd->status), strerror(errno));
+ cac_FreeHandle(hnd);
+ exit(-1);
+ }
+
+ printf("How many sids do you want to grab at a time? ");
+ fscanf(stdin, "%d", &max_sids);
+
+ struct LsaOpenPolicy lop;
+ ZERO_STRUCT(lop);
+
+ lop.in.access = SEC_RIGHT_MAXIMUM_ALLOWED;
+ lop.in.security_qos = True;
+
+
+ if(!cac_LsaOpenPolicy(hnd, mem_ctx, &lop)) {
+ fprintf(stderr, "Could not open policy handle.\n Error: %s\n", nt_errstr(hnd->status));
+ cac_FreeHandle(hnd);
+ exit(-1);
+ }
+
+ pol = lop.out.pol;
+
+
+ struct LsaEnumSids esop;
+ ZERO_STRUCT(esop);
+ esop.in.pol = pol;
+ /*grab a couple at a time to demonstrate multiple calls*/
+ esop.in.pref_max_sids = max_sids;
+
+ printf("Attempting to fetch SIDs %d at a time\n", esop.in.pref_max_sids);
+
+ while(cac_LsaEnumSids(hnd, mem_ctx, &esop)) {
+
+ printf("\nEnumerated %d sids: \n", esop.out.num_sids);
+ for(i = 0; i < esop.out.num_sids; i++) {
+ printf(" SID: %s\n", sid_string_static(&esop.out.sids[i]));
+ }
+
+ printf("Resolving names\n");
+
+ struct LsaGetNamesFromSids gnop;
+ ZERO_STRUCT(gnop);
+
+ gnop.in.pol = pol;
+ gnop.in.sids = esop.out.sids;
+ gnop.in.num_sids = esop.out.num_sids;
+
+ if(!cac_LsaGetNamesFromSids(hnd, mem_ctx, &gnop)) {
+ fprintf(stderr, "Could not resolve names.\n Error: %s\n", nt_errstr(hnd->status));
+ goto done;
+ }
+
+ printf("\nResolved %d names: \n", gnop.out.num_found);
+ for(i = 0; i < gnop.out.num_found; i++) {
+ printf(" SID: %s\n", sid_string_static(&gnop.out.sids[i].sid));
+ printf(" Name: %s\n", gnop.out.sids[i].name);
+ }
+
+ /*clean up a little*/
+ talloc_free(gnop.out.sids);
+ }
+
+done:
+ if(!cac_LsaClosePolicy(hnd, mem_ctx, pol)) {
+ fprintf(stderr, "Could not close policy handle.\n Error: %s\n", nt_errstr(hnd->status));
+ }
+
+ cac_FreeHandle(hnd);
+ talloc_destroy(mem_ctx);
+
+ return 0;
+}