1/*opens and closes a registry handle*/ 2 3#include "libmsrpc.h" 4 5int main() { 6 CacServerHandle *hnd = NULL; 7 TALLOC_CTX *mem_ctx = NULL; 8 9 POLICY_HND **keys = NULL; 10 11 char roots[4][50] = { {CAC_HKCR}, {CAC_HKLM}, {CAC_HKU}, {CAC_HKPD} }; 12 13 int i; 14 15 16 mem_ctx = talloc_init("regopen"); 17 18 hnd = cac_NewServerHandle(True); 19 20 keys = TALLOC_ARRAY(mem_ctx, POLICY_HND *, 4); 21 22 printf("Enter server to connect to: "); 23 fscanf(stdin, "%s", hnd->server); 24 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); 29 } 30 31 struct RegConnect rc; 32 ZERO_STRUCT(rc); 33 34 rc.in.access = SEC_RIGHT_MAXIMUM_ALLOWED; 35 36 for(i = 0; i < 4; i++) { 37 printf("opening: %s\n", roots[i]); 38 39 rc.in.root = roots[i]; 40 41 if(!cac_RegConnect(hnd, mem_ctx, &rc)) { 42 fprintf(stderr, " Could not connect to registry. %s\n", nt_errstr(hnd->status)); 43 continue; 44 } 45 46 keys[i] = rc.out.key; 47 } 48 49 for(i = 3; i >= 0; i--) { 50 if(keys[i] == NULL) 51 continue; 52 53 printf("closing: %s\n", roots[i]); 54 55 if(!cac_RegClose(hnd, mem_ctx, keys[i])) { 56 fprintf(stderr, " Could not close handle. %s\n", nt_errstr(hnd->status)); 57 } 58 } 59 60 cac_FreeHandle(hnd); 61 62 talloc_destroy(mem_ctx); 63 64 return 0; 65 66} 67