1 /* simple test code, opens and closes an LSA policy handle using libmsrpc, careful.. there's no password input masking*/
6 void fill_conn_info(CacServerHandle *hnd) {
12 fprintf(stdout, "Enter domain name: ");
13 fscanf(stdin, "%s", domain);
15 fprintf(stdout, "Enter username: ");
16 fscanf(stdin, "%s", username);
18 fprintf(stdout, "Enter password (no input masking): ");
19 fscanf(stdin, "%s", password);
21 fprintf(stdout, "Enter server (ip or name): ");
22 fscanf(stdin, "%s", server);
24 hnd->domain = SMB_STRDUP(domain);
25 hnd->username = SMB_STRDUP(username);
26 hnd->password = SMB_STRDUP(password);
27 hnd->server = SMB_STRDUP(server);
31 CacServerHandle *hnd = NULL;
33 struct LsaOpenPolicy op;
35 mem_ctx = talloc_init("lsapol");
38 hnd = cac_NewServerHandle(False);
40 /*this line is unnecesary*/
41 cac_SetAuthDataFn(hnd, cac_GetAuthDataFn);
47 /*connect to the server, its name/ip is already in the handle so just pass NULL*/
48 if(!cac_Connect(hnd, NULL)) {
49 fprintf(stderr, "Could not connect to server. \n Error %s\n errno(%d): %s\n", nt_errstr(hnd->status), errno, strerror(errno));
54 fprintf(stdout, "Connected to server\n");
57 op.in.access = GENERIC_EXECUTE_ACCESS;
58 op.in.security_qos = True;
61 if(!cac_LsaOpenPolicy(hnd, mem_ctx, &op)) {
62 fprintf(stderr, "Could not open policy.\n Error: %s.errno: %d.\n", nt_errstr(hnd->status), errno);
67 fprintf(stdout, "Opened Policy handle\n");
71 if(!cac_LsaClosePolicy(hnd, mem_ctx, op.out.pol)) {
72 fprintf(stderr, "Could not close policy. Error: %s\n", nt_errstr(hnd->status));
75 fprintf(stdout, "Closed Policy handle\n");
81 talloc_destroy(mem_ctx);
83 fprintf(stdout, "Free'd server handle\n");