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

regkeyenum.c File Reference

#include "libmsrpc.h"

Go to the source code of this file.

Defines

#define MAX_KEYS_PER_ENUM   3

Functions

int main ()


Define Documentation

#define MAX_KEYS_PER_ENUM   3
 

Definition at line 5 of file regkeyenum.c.


Function Documentation

int main void   ) 
 

enumerate all the subkeys

Definition at line 7 of file regkeyenum.c.

References cac_Connect(), cac_FreeHandle(), cac_NewServerHandle(), CAC_OP_FAILED, cac_RegClose(), cac_RegEnumKeys(), cac_RegOpenKey(), errno, fprintf(), RegEnumKeys::in, RegOpenKey::in, nt_errstr(), RegEnumKeys::out, RegOpenKey::out, printf(), REG_KEY_ALL, _CACSERVERHANDLE::server, _CACSERVERHANDLE::status, strerror, TALLOC_ARRAY, talloc_destroy, talloc_init(), True, and ZERO_STRUCT.

00007            {
00008    CacServerHandle *hnd = NULL;
00009     TALLOC_CTX *mem_ctx  = NULL;
00010  
00011     int num_keys;
00012 
00013     int max_enum;
00014 
00015     int i;
00016 
00017     fstring *key_names;
00018 
00019     mem_ctx = talloc_init("regkeyenum");
00020  
00021     hnd = cac_NewServerHandle(True);
00022 
00023     printf("Enter server to connect to: ");
00024     fscanf(stdin, "%s", hnd->server);
00025 
00026     printf("How many keys do you want to open?: ");
00027     fscanf(stdin, "%d", &num_keys);
00028 
00029     printf("How many keys per enum?: ");
00030     fscanf(stdin, "%d", &max_enum);
00031 
00032     key_names = TALLOC_ARRAY(mem_ctx, fstring , num_keys);
00033     if(!key_names) {
00034        fprintf(stderr, "No memory\n");
00035        exit(-1);
00036     }
00037 
00038     for(i = 0; i < num_keys; i++) {
00039        printf("Enter key to open: ");
00040        fscanf(stdin, "%s", key_names[i]);
00041     }
00042 
00043     if(!cac_Connect(hnd, NULL)) {
00044        fprintf(stderr, "Could not connect to server.\n Error: %s.\n errno: %s\n", nt_errstr(hnd->status), strerror(errno));
00045        cac_FreeHandle(hnd);
00046        exit(-1);
00047     }
00048 
00049     for(i = 0; i < num_keys; i++) {
00050        printf("trying to open key %s...\n", key_names[i]);
00051 
00052        struct RegOpenKey rok;
00053        ZERO_STRUCT(rok);
00054 
00055        rok.in.parent_key = NULL;
00056        rok.in.name   = key_names[i];
00057        rok.in.access = REG_KEY_ALL;
00058 
00059        if(!cac_RegOpenKey(hnd, mem_ctx, &rok)) {
00060           fprintf(stderr, "Could not open key %s\n Error: %s\n", rok.in.name, nt_errstr(hnd->status));
00061           continue;
00062        }
00063 
00065        printf("Enumerating all subkeys:\n");
00066 
00067        struct RegEnumKeys ek;
00068        ZERO_STRUCT(ek);
00069 
00070        ek.in.key = rok.out.key;
00071        ek.in.max_keys = max_enum;
00072 
00073        while(cac_RegEnumKeys(hnd, mem_ctx, &ek)) {
00074           int j;
00075 
00076           for(j = 0; j < ek.out.num_keys; j++) {
00077              printf(" Key name: %s\n", ek.out.key_names[j]);
00078           }
00079        }
00080 
00081        if(CAC_OP_FAILED(hnd->status)) {
00082           fprintf(stderr, "Could not enumerate keys: %s\n", nt_errstr(hnd->status));
00083           continue;
00084        }
00085 
00086        printf("closing key %s...\n", key_names[i]);
00087 
00088        if(!cac_RegClose(hnd, mem_ctx, rok.out.key)) {
00089           fprintf(stderr, "Could not close handle %s\n", nt_errstr(hnd->status));
00090        }
00091     }
00092 
00093     cac_FreeHandle(hnd);
00094 
00095     talloc_destroy(mem_ctx);
00096 
00097     return 0;
00098 
00099 }


© sourcejam.com 2005-2008