r25598: Add missing become_root/unbecome_root around calls of add_aliases.
[Samba/gebeck_regimport.git] / examples / libmsrpc / test / reg / security.c
blob6808f8c1f3454313c1c2f980835fca55887bc089
1 /*tests cac_RegSetKeySecurity()*/
3 #include "libmsrpc.h"
4 #include "test_util.h"
6 int main(int argc, char **argv) {
7 CacServerHandle *hnd = NULL;
8 TALLOC_CTX *mem_ctx = NULL;
10 fstring tmp;
12 mem_ctx = talloc_init("regsetval");
14 hnd = cac_NewServerHandle(True);
16 cac_SetAuthDataFn(hnd, cactest_GetAuthDataFn);
18 cac_parse_cmd_line(argc, argv, hnd);
20 if(!cac_Connect(hnd, NULL)) {
21 fprintf(stderr, "Could not connect to server %s. Error: %s\n", hnd->server, nt_errstr(hnd->status));
22 exit(-1);
25 struct RegOpenKey rok;
26 ZERO_STRUCT(rok);
28 printf("enter key to query: ");
29 cactest_readline(stdin, tmp);
31 rok.in.name = talloc_strdup(mem_ctx, tmp);
32 rok.in.access = REG_KEY_ALL;
34 if(!cac_RegOpenKey(hnd, mem_ctx, &rok)) {
35 fprintf(stderr, "Could not open key %s. Error %s\n", rok.in.name, nt_errstr(hnd->status));
36 exit(-1);
39 struct RegGetKeySecurity rks;
40 ZERO_STRUCT(rks);
42 rks.in.key = rok.out.key;
43 rks.in.info_type = ALL_SECURITY_INFORMATION;
45 if(!cac_RegGetKeySecurity(hnd, mem_ctx, &rks)) {
46 fprintf(stderr, "Could not query security for %s. Error: %s\n", rok.in.name, nt_errstr(hnd->status));
47 goto done;
50 printf("resetting key security...\n");
52 struct RegSetKeySecurity rss;
53 ZERO_STRUCT(rss);
55 rss.in.key = rok.out.key;
56 rss.in.info_type = ALL_SECURITY_INFORMATION;
57 rss.in.size = rks.out.size;
58 rss.in.descriptor = rks.out.descriptor;
60 if(!cac_RegSetKeySecurity(hnd, mem_ctx, &rss)) {
61 fprintf(stderr, "Could not set security. Error %s\n", nt_errstr(hnd->status));
64 done:
65 cac_RegClose(hnd, mem_ctx, rok.out.key);
67 cac_FreeHandle(hnd);
69 talloc_destroy(mem_ctx);
71 return 0;