00001
00002
00003 #include "includes.h"
00004 #include "libmsrpc.h"
00005
00006 void fill_conn_info(CacServerHandle *hnd) {
00007 pstring domain;
00008 pstring username;
00009 pstring password;
00010 pstring server;
00011
00012 fprintf(stdout, "Enter domain name: ");
00013 fscanf(stdin, "%s", domain);
00014
00015 fprintf(stdout, "Enter username: ");
00016 fscanf(stdin, "%s", username);
00017
00018 fprintf(stdout, "Enter password (no input masking): ");
00019 fscanf(stdin, "%s", password);
00020
00021 fprintf(stdout, "Enter server (ip or name): ");
00022 fscanf(stdin, "%s", server);
00023
00024 hnd->domain = SMB_STRDUP(domain);
00025 hnd->username = SMB_STRDUP(username);
00026 hnd->password = SMB_STRDUP(password);
00027 hnd->server = SMB_STRDUP(server);
00028 }
00029
00030 int main() {
00031 CacServerHandle *hnd = NULL;
00032 TALLOC_CTX *mem_ctx;
00033 struct LsaOpenPolicy op;
00034
00035 mem_ctx = talloc_init("lsapol");
00036
00037
00038 hnd = cac_NewServerHandle(False);
00039
00040
00041 cac_SetAuthDataFn(hnd, cac_GetAuthDataFn);
00042
00043 hnd->debug = 0;
00044
00045 fill_conn_info(hnd);
00046
00047
00048 if(!cac_Connect(hnd, NULL)) {
00049 fprintf(stderr, "Could not connect to server. \n Error %s\n errno(%d): %s\n", nt_errstr(hnd->status), errno, strerror(errno));
00050 cac_FreeHandle(hnd);
00051 exit(-1);
00052 }
00053 else {
00054 fprintf(stdout, "Connected to server\n");
00055 }
00056
00057 op.in.access = GENERIC_EXECUTE_ACCESS;
00058 op.in.security_qos = True;
00059
00060
00061 if(!cac_LsaOpenPolicy(hnd, mem_ctx, &op)) {
00062 fprintf(stderr, "Could not open policy.\n Error: %s.errno: %d.\n", nt_errstr(hnd->status), errno);
00063 cac_FreeHandle(hnd);
00064 exit(-1);
00065 }
00066 else {
00067 fprintf(stdout, "Opened Policy handle\n");
00068 }
00069
00070
00071 if(!cac_LsaClosePolicy(hnd, mem_ctx, op.out.pol)) {
00072 fprintf(stderr, "Could not close policy. Error: %s\n", nt_errstr(hnd->status));
00073 }
00074 else {
00075 fprintf(stdout, "Closed Policy handle\n");
00076 }
00077
00078
00079 cac_FreeHandle(hnd);
00080
00081 talloc_destroy(mem_ctx);
00082
00083 fprintf(stdout, "Free'd server handle\n");
00084
00085 return 0;
00086 }
00087