r25598: Add missing become_root/unbecome_root around calls of add_aliases.
[Samba/gebeck_regimport.git] / examples / libmsrpc / test / reg / regopen.c
blobfedc52e40d502bd79b90ead0d6c16a3b34aea533
1 /*opens and closes a registry handle*/
3 #include "libmsrpc.h"
5 int main() {
6 CacServerHandle *hnd = NULL;
7 TALLOC_CTX *mem_ctx = NULL;
9 POLICY_HND **keys = NULL;
11 char roots[4][50] = { {CAC_HKCR}, {CAC_HKLM}, {CAC_HKU}, {CAC_HKPD} };
13 int i;
16 mem_ctx = talloc_init("regopen");
18 hnd = cac_NewServerHandle(True);
20 keys = TALLOC_ARRAY(mem_ctx, POLICY_HND *, 4);
22 printf("Enter server to connect to: ");
23 fscanf(stdin, "%s", hnd->server);
25 if(!cac_Connect(hnd, NULL)) {
26 fprintf(stderr, "Could not connect to server.\n Error: %s.\n errno: %s\n", nt_errstr(hnd->status), strerror(errno));
27 cac_FreeHandle(hnd);
28 exit(-1);
31 struct RegConnect rc;
32 ZERO_STRUCT(rc);
34 rc.in.access = SEC_RIGHT_MAXIMUM_ALLOWED;
36 for(i = 0; i < 4; i++) {
37 printf("opening: %s\n", roots[i]);
39 rc.in.root = roots[i];
41 if(!cac_RegConnect(hnd, mem_ctx, &rc)) {
42 fprintf(stderr, " Could not connect to registry. %s\n", nt_errstr(hnd->status));
43 continue;
46 keys[i] = rc.out.key;
49 for(i = 3; i >= 0; i--) {
50 if(keys[i] == NULL)
51 continue;
53 printf("closing: %s\n", roots[i]);
55 if(!cac_RegClose(hnd, mem_ctx, keys[i])) {
56 fprintf(stderr, " Could not close handle. %s\n", nt_errstr(hnd->status));
60 cac_FreeHandle(hnd);
62 talloc_destroy(mem_ctx);
64 return 0;