Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

lsaenumprivs.c

Go to the documentation of this file.
00001 /*enumerates privileges*/
00002 
00003 #include "libmsrpc.h"
00004 #include "includes.h"
00005 
00006 #define MAX_STRING_LEN 50;
00007 
00008 int main() {
00009    CacServerHandle *hnd = NULL;
00010    TALLOC_CTX *mem_ctx  = NULL;
00011    POLICY_HND *lsa_pol  = NULL;
00012 
00013    int i;
00014 
00015    mem_ctx = talloc_init("lsatrust");
00016 
00017    hnd = cac_NewServerHandle(True);
00018 
00019    printf("Server: ");
00020    fscanf(stdin, "%s", hnd->server);
00021 
00022    printf("Connecting to server....\n");
00023 
00024    if(!cac_Connect(hnd, NULL)) {
00025       fprintf(stderr, "Could not connect to server.\n Error: %s\n errno %s\n", nt_errstr(hnd->status), strerror(errno));
00026       cac_FreeHandle(hnd);
00027       exit(-1);
00028    }
00029 
00030    printf("Connected to server\n");
00031 
00032    struct LsaOpenPolicy lop;
00033    ZERO_STRUCT(lop);
00034 
00035    lop.in.access = SEC_RIGHT_MAXIMUM_ALLOWED;
00036    lop.in.security_qos = True;
00037 
00038 
00039    if(!cac_LsaOpenPolicy(hnd, mem_ctx, &lop)) {
00040       fprintf(stderr, "Could not open policy handle.\n Error: %s\n", nt_errstr(hnd->status));
00041       cac_FreeHandle(hnd);
00042       exit(-1);
00043    }
00044 
00045    lsa_pol = lop.out.pol;
00046 
00047    printf("Enumerating Privileges\n");
00048 
00049    struct LsaEnumPrivileges ep;
00050    ZERO_STRUCT(ep);
00051 
00052    ep.in.pol = lsa_pol;
00053    ep.in.pref_max_privs = 50;
00054 
00055    while(cac_LsaEnumPrivileges(hnd, mem_ctx, &ep)) {
00056       printf(" Enumerated %d privileges\n", ep.out.num_privs);
00057 
00058       for(i = 0; i < ep.out.num_privs; i++) {
00059          printf("\"%s\"\n", ep.out.priv_names[i]);
00060       }
00061 
00062       printf("\n");
00063    }
00064 
00065    if(CAC_OP_FAILED(hnd->status)) {
00066       fprintf(stderr, "Error while enumerating privileges.\n Error: %s\n", nt_errstr(hnd->status));
00067       goto done;
00068    }
00069 
00070 done:
00071    if(!cac_LsaClosePolicy(hnd, mem_ctx, lsa_pol)) {
00072       fprintf(stderr, "Could not close policy handle.\n Error: %s\n", nt_errstr(hnd->status));
00073    }
00074 
00075    cac_FreeHandle(hnd);
00076    talloc_destroy(mem_ctx);
00077 
00078    return 0;
00079 }

© sourcejam.com 2005-2008