00001
00002
00003 #include "libmsrpc.h"
00004 #include "test_util.h"
00005
00006 #define MAX_KEYS_PER_ENUM 3
00007
00008 int main(int argc, char **argv) {
00009 CacServerHandle *hnd = NULL;
00010 TALLOC_CTX *mem_ctx = NULL;
00011
00012 fstring key_name;
00013
00014 fstring val_name;
00015
00016 mem_ctx = talloc_init("regqueryval");
00017
00018 hnd = cac_NewServerHandle(True);
00019
00020 cac_SetAuthDataFn(hnd, cactest_GetAuthDataFn);
00021
00022 cac_parse_cmd_line(argc, argv, hnd);
00023
00024 printf("Enter key to open: ");
00025 fscanf(stdin, "%s", key_name);
00026
00027 printf("Enter value to query: ");
00028 fscanf(stdin, "%s", val_name);
00029
00030 if(!cac_Connect(hnd, NULL)) {
00031 fprintf(stderr, "Could not connect to server.\n Error: %s.\n errno: %s\n", nt_errstr(hnd->status), strerror(errno));
00032 cac_FreeHandle(hnd);
00033 exit(-1);
00034 }
00035
00036 printf("trying to open key %s...\n", key_name);
00037
00038 struct RegOpenKey rok;
00039 ZERO_STRUCT(rok);
00040
00041 rok.in.parent_key = NULL;
00042 rok.in.name = key_name;
00043 rok.in.access = REG_KEY_ALL;
00044
00045 if(!cac_RegOpenKey(hnd, mem_ctx, &rok)) {
00046 fprintf(stderr, "Could not open key %s\n Error: %s\n", rok.in.name, nt_errstr(hnd->status));
00047 goto done;
00048 }
00049
00050 struct RegQueryValue rqv;
00051 ZERO_STRUCT(rqv);
00052
00053 rqv.in.key = rok.out.key;
00054 rqv.in.val_name = talloc_strdup(mem_ctx, val_name);
00055
00056 printf("querying value %s...\n", rqv.in.val_name);
00057 if(!cac_RegQueryValue(hnd, mem_ctx, &rqv)) {
00058 fprintf(stderr, "Could not query value. Error: %s\n", nt_errstr(hnd->status));
00059 }
00060 else {
00061 printf("Queried value %s\n", rqv.in.val_name);
00062 print_value(rqv.out.type, rqv.out.data);
00063 }
00064
00065
00066 printf("closing key %s...\n", key_name);
00067
00068 if(!cac_RegClose(hnd, mem_ctx, rok.out.key)) {
00069 fprintf(stderr, "Could not close handle %s\n", nt_errstr(hnd->status));
00070 }
00071
00072 done:
00073 cac_FreeHandle(hnd);
00074
00075 talloc_destroy(mem_ctx);
00076
00077 return 0;
00078
00079 }