#include "libmsrpc.h"Go to the source code of this file.
Defines | |
| #define | MAX_KEYS_PER_ENUM 3 |
Functions | |
| int | main () |
|
|
Definition at line 5 of file regkeycreate.c. |
|
|
enumerate all the subkeys Definition at line 7 of file regkeycreate.c. References cac_Connect(), cac_FreeHandle(), cac_NewServerHandle(), CAC_OP_FAILED, cac_RegClose(), cac_RegCreateKey(), cac_RegDeleteKey(), cac_RegEnumKeys(), cac_RegOpenKey(), errno, fprintf(), RegDeleteKey::in, RegEnumKeys::in, RegCreateKey::in, RegOpenKey::in, nt_errstr(), RegEnumKeys::out, RegCreateKey::out, RegOpenKey::out, printf(), REG_KEY_ALL, _CACSERVERHANDLE::server, _CACSERVERHANDLE::status, strerror, talloc_destroy, talloc_init(), talloc_strdup(), True, and ZERO_STRUCT. 00007 { 00008 CacServerHandle *hnd = NULL; 00009 TALLOC_CTX *mem_ctx = NULL; 00010 00011 fstring key_name; 00012 00013 fstring key_to_create; 00014 00015 mem_ctx = talloc_init("regcreatekey"); 00016 00017 hnd = cac_NewServerHandle(True); 00018 00019 printf("Enter server to connect to: "); 00020 fscanf(stdin, "%s", hnd->server); 00021 00022 printf("Enter key to open: "); 00023 fscanf(stdin, "%s", key_name); 00024 00025 printf("Enter key to create: "); 00026 fscanf(stdin, "%s", key_to_create); 00027 00028 if(!cac_Connect(hnd, NULL)) { 00029 fprintf(stderr, "Could not connect to server.\n Error: %s.\n errno: %s\n", nt_errstr(hnd->status), strerror(errno)); 00030 cac_FreeHandle(hnd); 00031 exit(-1); 00032 } 00033 00034 printf("trying to open key %s...\n", key_name); 00035 00036 struct RegOpenKey rok; 00037 ZERO_STRUCT(rok); 00038 00039 rok.in.parent_key = NULL; 00040 rok.in.name = key_name; 00041 rok.in.access = REG_KEY_ALL; 00042 00043 if(!cac_RegOpenKey(hnd, mem_ctx, &rok)) { 00044 fprintf(stderr, "Could not open key %s\n Error: %s\n", rok.in.name, nt_errstr(hnd->status)); 00045 goto done; 00046 } 00047 00048 printf("Creating key %s...\n", key_to_create); 00049 00050 struct RegCreateKey rck; 00051 ZERO_STRUCT(rck); 00052 00053 rck.in.parent_key = rok.out.key; 00054 rck.in.key_name = talloc_strdup(mem_ctx, key_to_create); 00055 rck.in.class_name = talloc_strdup(mem_ctx, ""); 00056 rck.in.access = REG_KEY_ALL; 00057 00058 if(!cac_RegCreateKey(hnd, mem_ctx, &rck)) { 00059 fprintf(stderr, "Could not create key. Error %s\n", nt_errstr(hnd->status)); 00060 goto done; 00061 } 00062 00063 if(!cac_RegClose(hnd, mem_ctx, rck.out.key)) { 00064 fprintf(stderr, "Could not close key. Error %s\n", nt_errstr(hnd->status)); 00065 goto done; 00066 } 00067 00069 printf("Enumerating all subkeys:\n"); 00070 00071 struct RegEnumKeys ek; 00072 ZERO_STRUCT(ek); 00073 00074 ek.in.key = rok.out.key; 00075 ek.in.max_keys = 50; 00076 00077 while(cac_RegEnumKeys(hnd, mem_ctx, &ek)) { 00078 int j; 00079 00080 for(j = 0; j < ek.out.num_keys; j++) { 00081 printf(" Key name: %s\n", ek.out.key_names[j]); 00082 } 00083 } 00084 00085 if(CAC_OP_FAILED(hnd->status)) { 00086 fprintf(stderr, "Could not enumerate keys: %s\n", nt_errstr(hnd->status)); 00087 goto done; 00088 } 00089 00090 printf("deleting key %s\n", key_to_create); 00091 00092 struct RegDeleteKey rdk; 00093 ZERO_STRUCT(rdk); 00094 00095 rdk.in.parent_key = rok.out.key; 00096 rdk.in.name = key_to_create; 00097 00098 if(!cac_RegDeleteKey(hnd, mem_ctx, &rdk)) { 00099 fprintf(stderr, "Could not delete key. Error %s\n", nt_errstr(hnd->status)); 00100 } 00101 00102 printf("closing key %s...\n", key_name); 00103 00104 if(!cac_RegClose(hnd, mem_ctx, rok.out.key)) { 00105 fprintf(stderr, "Could not close handle %s\n", nt_errstr(hnd->status)); 00106 } 00107 00108 done: 00109 cac_FreeHandle(hnd); 00110 00111 talloc_destroy(mem_ctx); 00112 00113 return 0; 00114 00115 }
|