00001
00002
00003 #include "libmsrpc.h"
00004
00005 int main() {
00006 CacServerHandle *hnd = NULL;
00007 TALLOC_CTX *mem_ctx = NULL;
00008
00009 int num_keys;
00010 int i;
00011
00012 fstring *key_names;
00013
00014 mem_ctx = talloc_init("regopenkey");
00015
00016 hnd = cac_NewServerHandle(True);
00017
00018 printf("Enter server to connect to: ");
00019 fscanf(stdin, "%s", hnd->server);
00020
00021 printf("How many keys do you want to open?: ");
00022 fscanf(stdin, "%d", &num_keys);
00023
00024 key_names = TALLOC_ARRAY(mem_ctx, fstring , num_keys);
00025 if(!key_names) {
00026 fprintf(stderr, "No memory\n");
00027 exit(-1);
00028 }
00029
00030 for(i = 0; i < num_keys; i++) {
00031 printf("Enter key to open: ");
00032 fscanf(stdin, "%s", key_names[i]);
00033 }
00034
00035 if(!cac_Connect(hnd, NULL)) {
00036 fprintf(stderr, "Could not connect to server.\n Error: %s.\n errno: %s\n", nt_errstr(hnd->status), strerror(errno));
00037 cac_FreeHandle(hnd);
00038 exit(-1);
00039 }
00040
00041 for(i = 0; i < num_keys; i++) {
00042 printf("trying to open key %s...\n", key_names[i]);
00043
00044 struct RegOpenKey rok;
00045 ZERO_STRUCT(rok);
00046
00047 rok.in.parent_key = NULL;
00048 rok.in.name = key_names[i];
00049 rok.in.access = REG_KEY_ALL;
00050
00051 if(!cac_RegOpenKey(hnd, mem_ctx, &rok)) {
00052 fprintf(stderr, "Could not open key %s\n Error: %s\n", rok.in.name, nt_errstr(hnd->status));
00053 continue;
00054 }
00055
00056 printf("closing key %s...\n", key_names[i]);
00057
00058 if(!cac_RegClose(hnd, mem_ctx, rok.out.key)) {
00059 fprintf(stderr, "Could not close handle %s\n", nt_errstr(hnd->status));
00060 }
00061 }
00062
00063 cac_FreeHandle(hnd);
00064
00065 talloc_destroy(mem_ctx);
00066
00067 return 0;
00068
00069 }