diff options
author | Gerald Carter <jerry@samba.org> | 2005-09-03 16:55:45 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 11:03:30 -0500 |
commit | 3c6b0f965588aab0edbc4d115fb9e72c884ded3b (patch) | |
tree | ce3740784555e729297955c924e4701feaf69d38 /examples/libmsrpc/test/reg/regkey.c | |
parent | a44e97c99f61916db3f7cc02cd2581c8d64be73a (diff) | |
download | samba-3c6b0f965588aab0edbc4d115fb9e72c884ded3b.tar.gz samba-3c6b0f965588aab0edbc4d115fb9e72c884ded3b.tar.bz2 samba-3c6b0f965588aab0edbc4d115fb9e72c884ded3b.zip |
r10003: in the rush for 10k, I forgot to run add the rest of Chris' libmsrpc files
(This used to be commit 32bebc452dffa8348b94c5b866350b1fe761986f)
Diffstat (limited to 'examples/libmsrpc/test/reg/regkey.c')
-rw-r--r-- | examples/libmsrpc/test/reg/regkey.c | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/examples/libmsrpc/test/reg/regkey.c b/examples/libmsrpc/test/reg/regkey.c new file mode 100644 index 0000000000..a90d06c6ef --- /dev/null +++ b/examples/libmsrpc/test/reg/regkey.c @@ -0,0 +1,76 @@ +/*opens and closes a key*/ + +#include "libmsrpc.h" + +int main() { + CacServerHandle *hnd = NULL; + TALLOC_CTX *mem_ctx = NULL; + + fstring key; + + mem_ctx = talloc_init("regkey"); + + hnd = cac_NewServerHandle(False); + + /*allocate some memory so get_auth_data_fn can do it's magic*/ + hnd->username = SMB_MALLOC_ARRAY(char, sizeof(fstring)); + hnd->domain = SMB_MALLOC_ARRAY(char, sizeof(fstring)); + hnd->netbios_name = SMB_MALLOC_ARRAY(char, sizeof(fstring)); + hnd->password = SMB_MALLOC_ARRAY(char, sizeof(fstring)); + + hnd->server = SMB_MALLOC_ARRAY(char, sizeof(fstring)); + + printf("Enter server to connect to: "); + fscanf(stdin, "%s", hnd->server); + + printf("Enter key to open: "); + fscanf(stdin, "%s", key); + + if(!cac_Connect(hnd, NULL)) { + fprintf(stderr, "Could not connect to server.\n Error: %s.\n errno: %s\n", nt_errstr(hnd->status), strerror(errno)); + cac_FreeHandle(hnd); + exit(-1); + } + + struct RegConnect rc; + ZERO_STRUCT(rc); + + rc.in.access = REG_KEY_ALL; + rc.in.root = HKEY_LOCAL_MACHINE; + + if(!cac_RegConnect(hnd, mem_ctx, &rc)) { + fprintf(stderr, " Could not connect to registry. %s\n", nt_errstr(hnd->status)); + goto done; + } + + printf("trying to open key %s...\n", key); + + + struct RegOpenKey rok; + ZERO_STRUCT(rok); + + rok.in.parent_key = rc.out.key; + rok.in.name = key; + rok.in.access = REG_KEY_ALL; + + if(!cac_RegOpenKey(hnd, mem_ctx, &rok)) { + fprintf(stderr, "Could not open key %s\n Error: %s\n", rok.in.name, nt_errstr(hnd->status)); + goto done; + } + + if(!cac_RegClose(hnd, mem_ctx, rok.out.key)) { + fprintf(stderr, "Could not close handle %s\n", nt_errstr(hnd->status)); + } + + if(!cac_RegClose(hnd, mem_ctx, rc.out.key)) { + fprintf(stderr, " Could not close handle. %s\n", nt_errstr(hnd->status)); + } + +done: + cac_FreeHandle(hnd); + + talloc_destroy(mem_ctx); + + return 0; + +} |