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

lsapriv.c

Go to the documentation of this file.
00001 /*tries to set privileges for an account*/
00002 
00003 #include "libmsrpc.h"
00004 #include "test_util.h"
00005 
00006 #define BIGGEST_UINT32 0xffffffff
00007 
00008 int main(int argc, char **argv) {
00009    CacServerHandle *hnd = NULL;
00010    TALLOC_CTX *mem_ctx = NULL;
00011             
00012    struct LsaOpenPolicy lop;
00013    struct LsaEnumPrivileges ep;
00014    struct LsaEnumAccountRights ar;
00015    struct LsaAddPrivileges ap;
00016    
00017    fstring tmp;
00018 
00019    uint32 i = 0;
00020    
00021    mem_ctx = talloc_init("lsapriv");
00022 
00023    hnd = cac_NewServerHandle(True);
00024 
00025    cac_SetAuthDataFn(hnd, cactest_GetAuthDataFn);
00026 
00027    cac_parse_cmd_line(argc, argv, hnd);
00028 
00029    if(!cac_Connect(hnd, NULL)) {
00030       fprintf(stderr, "Could not connect to server %s. Error: %s\n", hnd->server, nt_errstr(hnd->status));
00031       exit(-1);
00032    }
00033 
00034    ZERO_STRUCT(lop);
00035 
00036    lop.in.access = SEC_RIGHT_MAXIMUM_ALLOWED;
00037 
00038    if(!cac_LsaOpenPolicy(hnd, mem_ctx, &lop)) {
00039       fprintf(stderr, "Could not open LSA policy. Error: %s\n", nt_errstr(hnd->status));
00040       goto done;
00041    }
00042 
00043    /*first enumerate possible privileges*/
00044    ZERO_STRUCT(ep);
00045 
00046    ep.in.pol = lop.out.pol;
00047    ep.in.pref_max_privs = BIGGEST_UINT32;
00048 
00049    printf("Enumerating supported privileges:\n");
00050    while(cac_LsaEnumPrivileges(hnd, mem_ctx, &ep)) {
00051       for(i = 0; i < ep.out.num_privs; i++) {
00052          printf("\t%s\n", ep.out.priv_names[i]);
00053       }
00054    }
00055 
00056    if(CAC_OP_FAILED(hnd->status)) {
00057       fprintf(stderr, "Could not enumerate privileges. Error: %s\n", nt_errstr(hnd->status));
00058       goto done;
00059    }
00060 
00061    printf("Enter account name: ");
00062    cactest_readline(stdin, tmp);
00063 
00064    ZERO_STRUCT(ar);
00065 
00066    ar.in.pol = lop.out.pol;
00067    ar.in.name = talloc_strdup(mem_ctx, tmp);
00068    
00069    printf("Enumerating privileges for %s:\n", ar.in.name);
00070    if(!cac_LsaEnumAccountRights(hnd, mem_ctx, &ar)) {
00071       fprintf(stderr, "Could not enumerate privileges. Error: %s\n", nt_errstr(hnd->status));
00072       goto done;
00073    }
00074 
00075    printf("Enumerated %d privileges:\n", ar.out.num_privs);
00076 
00077    for(i = 0; i < ar.out.num_privs; i++) 
00078       printf("\t%s\n", ar.out.priv_names[i]);
00079 
00080    ZERO_STRUCT(ap);
00081 
00082    ap.in.pol = lop.out.pol;
00083    ap.in.name = ar.in.name;
00084 
00085    printf("How many privileges will you set: ");
00086    scanf("%d", &ap.in.num_privs);
00087 
00088    ap.in.priv_names = talloc_array(mem_ctx, char *, ap.in.num_privs);
00089    if(!ap.in.priv_names) {
00090       fprintf(stderr, "No memory\n");
00091       goto done;
00092    }
00093 
00094    for(i = 0; i < ap.in.num_privs; i++) {
00095       printf("Enter priv %d: ", i);
00096       cactest_readline(stdin, tmp);
00097 
00098       ap.in.priv_names[i] = talloc_strdup(mem_ctx, tmp);
00099    }
00100 
00101    if(!cac_LsaSetPrivileges(hnd, mem_ctx, &ap)) {
00102       fprintf(stderr, "Could not set privileges. Error: %s\n", nt_errstr(hnd->status));
00103       goto done;
00104    }
00105 
00106 done:
00107    talloc_destroy(mem_ctx);
00108    cac_FreeHandle(hnd);
00109 
00110    return 0;
00111 
00112 }
00113 

© sourcejam.com 2005-2008