summaryrefslogtreecommitdiff
path: root/examples/libmsrpc/test/lsa/lsapol.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/lsapol.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/lsapol.c')
-rw-r--r--examples/libmsrpc/test/lsa/lsapol.c87
1 files changed, 87 insertions, 0 deletions
diff --git a/examples/libmsrpc/test/lsa/lsapol.c b/examples/libmsrpc/test/lsa/lsapol.c
new file mode 100644
index 0000000000..58407e4343
--- /dev/null
+++ b/examples/libmsrpc/test/lsa/lsapol.c
@@ -0,0 +1,87 @@
+/* simple test code, opens and closes an LSA policy handle using libmsrpc, careful.. there's no password input masking*/
+
+#include "includes.h"
+#include "libmsrpc.h"
+
+void fill_conn_info(CacServerHandle *hnd) {
+ pstring domain;
+ pstring username;
+ pstring password;
+ pstring server;
+
+ fprintf(stdout, "Enter domain name: ");
+ fscanf(stdin, "%s", domain);
+
+ fprintf(stdout, "Enter username: ");
+ fscanf(stdin, "%s", username);
+
+ fprintf(stdout, "Enter password (no input masking): ");
+ fscanf(stdin, "%s", password);
+
+ fprintf(stdout, "Enter server (ip or name): ");
+ fscanf(stdin, "%s", server);
+
+ hnd->domain = SMB_STRDUP(domain);
+ hnd->username = SMB_STRDUP(username);
+ hnd->password = SMB_STRDUP(password);
+ hnd->server = SMB_STRDUP(server);
+}
+
+int main() {
+ CacServerHandle *hnd = NULL;
+ TALLOC_CTX *mem_ctx;
+ struct LsaOpenPolicy op;
+
+ mem_ctx = talloc_init("lsapol");
+
+
+ hnd = cac_NewServerHandle(False);
+
+ /*this line is unnecesary*/
+ cac_SetAuthDataFn(hnd, cac_GetAuthDataFn);
+
+ hnd->debug = 0;
+
+ fill_conn_info(hnd);
+
+ /*connect to the server, its name/ip is already in the handle so just pass NULL*/
+ if(!cac_Connect(hnd, NULL)) {
+ fprintf(stderr, "Could not connect to server. \n Error %s\n errno(%d): %s\n", nt_errstr(hnd->status), errno, strerror(errno));
+ cac_FreeHandle(hnd);
+ exit(-1);
+ }
+ else {
+ fprintf(stdout, "Connected to server\n");
+ }
+
+ op.in.access = GENERIC_EXECUTE_ACCESS;
+ op.in.security_qos = True;
+
+ /*open the handle*/
+ if(!cac_LsaOpenPolicy(hnd, mem_ctx, &op)) {
+ fprintf(stderr, "Could not open policy.\n Error: %s.errno: %d.\n", nt_errstr(hnd->status), errno);
+ cac_FreeHandle(hnd);
+ exit(-1);
+ }
+ else {
+ fprintf(stdout, "Opened Policy handle\n");
+ }
+
+ /*close the handle*/
+ if(!cac_LsaClosePolicy(hnd, mem_ctx, op.out.pol)) {
+ fprintf(stderr, "Could not close policy. Error: %s\n", nt_errstr(hnd->status));
+ }
+ else {
+ fprintf(stdout, "Closed Policy handle\n");
+ }
+
+ /*cleanup*/
+ cac_FreeHandle(hnd);
+
+ talloc_destroy(mem_ctx);
+
+ fprintf(stdout, "Free'd server handle\n");
+
+ return 0;
+}
+