Samba 3: added Samba 3.0.24 sources
[tomato.git] / release / src / router / samba3 / examples / libmsrpc / test / reg / regqueryval.c
blob9989651898de6068445b98075449cc4800752ffd
1 /*tests cac_RegQueryValue()*/
3 #include "libmsrpc.h"
4 #include "test_util.h"
6 #define MAX_KEYS_PER_ENUM 3
8 int main(int argc, char **argv) {
9 CacServerHandle *hnd = NULL;
10 TALLOC_CTX *mem_ctx = NULL;
12 fstring key_name;
14 fstring val_name;
16 mem_ctx = talloc_init("regqueryval");
18 hnd = cac_NewServerHandle(True);
20 cac_SetAuthDataFn(hnd, cactest_GetAuthDataFn);
22 cac_parse_cmd_line(argc, argv, hnd);
24 printf("Enter key to open: ");
25 fscanf(stdin, "%s", key_name);
27 printf("Enter value to query: ");
28 fscanf(stdin, "%s", val_name);
30 if(!cac_Connect(hnd, NULL)) {
31 fprintf(stderr, "Could not connect to server.\n Error: %s.\n errno: %s\n", nt_errstr(hnd->status), strerror(errno));
32 cac_FreeHandle(hnd);
33 exit(-1);
36 printf("trying to open key %s...\n", key_name);
38 struct RegOpenKey rok;
39 ZERO_STRUCT(rok);
41 rok.in.parent_key = NULL;
42 rok.in.name = key_name;
43 rok.in.access = REG_KEY_ALL;
45 if(!cac_RegOpenKey(hnd, mem_ctx, &rok)) {
46 fprintf(stderr, "Could not open key %s\n Error: %s\n", rok.in.name, nt_errstr(hnd->status));
47 goto done;
50 struct RegQueryValue rqv;
51 ZERO_STRUCT(rqv);
53 rqv.in.key = rok.out.key;
54 rqv.in.val_name = talloc_strdup(mem_ctx, val_name);
56 printf("querying value %s...\n", rqv.in.val_name);
57 if(!cac_RegQueryValue(hnd, mem_ctx, &rqv)) {
58 fprintf(stderr, "Could not query value. Error: %s\n", nt_errstr(hnd->status));
60 else {
61 printf("Queried value %s\n", rqv.in.val_name);
62 print_value(rqv.out.type, rqv.out.data);
66 printf("closing key %s...\n", key_name);
68 if(!cac_RegClose(hnd, mem_ctx, rok.out.key)) {
69 fprintf(stderr, "Could not close handle %s\n", nt_errstr(hnd->status));
72 done:
73 cac_FreeHandle(hnd);
75 talloc_destroy(mem_ctx);
77 return 0;