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

regvalenum.c File Reference

#include "libmsrpc.h"
#include "test_util.h"

Go to the source code of this file.

Defines

#define MAX_KEYS_PER_ENUM   3

Functions

int main (int argc, char **argv)


Define Documentation

#define MAX_KEYS_PER_ENUM   3
 

Definition at line 6 of file regvalenum.c.


Function Documentation

int main int  argc,
char **  argv
 

enumerate all the subkeys

Definition at line 9 of file regvalenum.c.

References cac_Connect(), cac_FreeHandle(), cac_NewServerHandle(), CAC_OP_FAILED, cac_parse_cmd_line(), cac_RegClose(), cac_RegEnumValues(), cac_RegOpenKey(), cac_SetAuthDataFn(), cactest_GetAuthDataFn(), errno, fprintf(), RegEnumValues::in, RegOpenKey::in, nt_errstr(), RegEnumValues::out, RegOpenKey::out, print_value(), printf(), REG_KEY_ALL, _CACSERVERHANDLE::status, strerror, TALLOC_ARRAY, talloc_destroy, talloc_init(), True, and ZERO_STRUCT.

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


© sourcejam.com 2005-2008