diff options
author | Gerald Carter <jerry@samba.org> | 2005-09-03 16:55:45 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 11:03:30 -0500 |
commit | 3c6b0f965588aab0edbc4d115fb9e72c884ded3b (patch) | |
tree | ce3740784555e729297955c924e4701feaf69d38 /examples/libmsrpc/test/lsa/lsapriv.c | |
parent | a44e97c99f61916db3f7cc02cd2581c8d64be73a (diff) | |
download | samba-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/lsapriv.c')
-rw-r--r-- | examples/libmsrpc/test/lsa/lsapriv.c | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/examples/libmsrpc/test/lsa/lsapriv.c b/examples/libmsrpc/test/lsa/lsapriv.c new file mode 100644 index 0000000000..80b3ea102f --- /dev/null +++ b/examples/libmsrpc/test/lsa/lsapriv.c @@ -0,0 +1,113 @@ +/*tries to set privileges for an account*/ + +#include "libmsrpc.h" +#include "test_util.h" + +#define BIGGEST_UINT32 0xffffffff + +int main(int argc, char **argv) { + CacServerHandle *hnd = NULL; + TALLOC_CTX *mem_ctx = NULL; + + struct LsaOpenPolicy lop; + struct LsaEnumPrivileges ep; + struct LsaEnumAccountRights ar; + struct LsaAddPrivileges ap; + + fstring tmp; + + uint32 i = 0; + + mem_ctx = talloc_init("lsapriv"); + + hnd = cac_NewServerHandle(True); + + cac_SetAuthDataFn(hnd, cactest_GetAuthDataFn); + + cac_parse_cmd_line(argc, argv, hnd); + + if(!cac_Connect(hnd, NULL)) { + fprintf(stderr, "Could not connect to server %s. Error: %s\n", hnd->server, nt_errstr(hnd->status)); + exit(-1); + } + + ZERO_STRUCT(lop); + + lop.in.access = SEC_RIGHT_MAXIMUM_ALLOWED; + + if(!cac_LsaOpenPolicy(hnd, mem_ctx, &lop)) { + fprintf(stderr, "Could not open LSA policy. Error: %s\n", nt_errstr(hnd->status)); + goto done; + } + + /*first enumerate possible privileges*/ + ZERO_STRUCT(ep); + + ep.in.pol = lop.out.pol; + ep.in.pref_max_privs = BIGGEST_UINT32; + + printf("Enumerating supported privileges:\n"); + while(cac_LsaEnumPrivileges(hnd, mem_ctx, &ep)) { + for(i = 0; i < ep.out.num_privs; i++) { + printf("\t%s\n", ep.out.priv_names[i]); + } + } + + if(CAC_OP_FAILED(hnd->status)) { + fprintf(stderr, "Could not enumerate privileges. Error: %s\n", nt_errstr(hnd->status)); + goto done; + } + + printf("Enter account name: "); + cactest_readline(stdin, tmp); + + ZERO_STRUCT(ar); + + ar.in.pol = lop.out.pol; + ar.in.name = talloc_strdup(mem_ctx, tmp); + + printf("Enumerating privileges for %s:\n", ar.in.name); + if(!cac_LsaEnumAccountRights(hnd, mem_ctx, &ar)) { + fprintf(stderr, "Could not enumerate privileges. Error: %s\n", nt_errstr(hnd->status)); + goto done; + } + + printf("Enumerated %d privileges:\n", ar.out.num_privs); + + for(i = 0; i < ar.out.num_privs; i++) + printf("\t%s\n", ar.out.priv_names[i]); + + ZERO_STRUCT(ap); + + ap.in.pol = lop.out.pol; + ap.in.name = ar.in.name; + + printf("How many privileges will you set: "); + scanf("%d", &ap.in.num_privs); + + ap.in.priv_names = talloc_array(mem_ctx, char *, ap.in.num_privs); + if(!ap.in.priv_names) { + fprintf(stderr, "No memory\n"); + goto done; + } + + for(i = 0; i < ap.in.num_privs; i++) { + printf("Enter priv %d: ", i); + cactest_readline(stdin, tmp); + + ap.in.priv_names[i] = talloc_strdup(mem_ctx, tmp); + } + + if(!cac_LsaSetPrivileges(hnd, mem_ctx, &ap)) { + fprintf(stderr, "Could not set privileges. Error: %s\n", nt_errstr(hnd->status)); + goto done; + } + +done: + talloc_destroy(mem_ctx); + cac_FreeHandle(hnd); + + return 0; + +} + |