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

regopen.c

Go to the documentation of this file.
00001 /*opens and closes a registry handle*/
00002 
00003 #include "libmsrpc.h"
00004 
00005 int main() {
00006    CacServerHandle *hnd = NULL;
00007     TALLOC_CTX *mem_ctx  = NULL;
00008  
00009     POLICY_HND **keys      = NULL;
00010 
00011     char roots[4][50] = { {CAC_HKCR}, {CAC_HKLM}, {CAC_HKU}, {CAC_HKPD} };
00012 
00013     int i;
00014  
00015 
00016     mem_ctx = talloc_init("regopen");
00017  
00018     hnd = cac_NewServerHandle(True);
00019 
00020     keys = TALLOC_ARRAY(mem_ctx, POLICY_HND *, 4);
00021     
00022     printf("Enter server to connect to: ");
00023     fscanf(stdin, "%s", hnd->server);
00024 
00025     if(!cac_Connect(hnd, NULL)) {
00026        fprintf(stderr, "Could not connect to server.\n Error: %s.\n errno: %s\n", nt_errstr(hnd->status), strerror(errno));
00027        cac_FreeHandle(hnd);
00028        exit(-1);
00029     }
00030 
00031     struct RegConnect rc;
00032     ZERO_STRUCT(rc);
00033 
00034     rc.in.access = SEC_RIGHT_MAXIMUM_ALLOWED;
00035 
00036     for(i = 0; i < 4; i++) {
00037        printf("opening: %s\n", roots[i]);
00038 
00039        rc.in.root = roots[i];
00040 
00041        if(!cac_RegConnect(hnd, mem_ctx, &rc)) {
00042           fprintf(stderr, " Could not connect to registry. %s\n", nt_errstr(hnd->status));
00043           continue;
00044        }
00045 
00046        keys[i] = rc.out.key;
00047     }
00048 
00049     for(i = 3; i >= 0; i--) {
00050        if(keys[i] == NULL)
00051           continue;
00052 
00053        printf("closing: %s\n", roots[i]);
00054 
00055        if(!cac_RegClose(hnd, mem_ctx, keys[i])) {
00056           fprintf(stderr, " Could not close handle. %s\n", nt_errstr(hnd->status));
00057        }
00058     }
00059 
00060     cac_FreeHandle(hnd);
00061 
00062     talloc_destroy(mem_ctx);
00063 
00064     return 0;
00065 
00066 }

© sourcejam.com 2005-2008