Changeset 988 for vendor/current/source3/utils/eventlogadm.c
- Timestamp:
- Nov 24, 2016, 1:14:11 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source3/utils/eventlogadm.c
r740 r988 26 26 #include "lib/eventlog/eventlog.h" 27 27 #include "registry.h" 28 #include "registry/reg_api.h" 29 #include "registry/reg_init_basic.h" 30 #include "registry/reg_util_token.h" 28 31 #include "registry/reg_backend_db.h" 29 #include "registry/reg_objects.h"30 32 #include "../libcli/registry/util_reg.h" 31 33 … … 79 81 const char **wrklist, **wp; 80 82 char *evtlogpath = NULL; 81 struct regsubkey_ctr *subkeys;82 struct regval_ctr *values;83 struct regval_blob *rval;84 83 int ii = 0; 85 84 bool already_in; 86 85 int i; 87 86 int numsources = 0; 88 TALLOC_CTX *ctx = talloc_ tos();87 TALLOC_CTX *ctx = talloc_stackframe(); 89 88 WERROR werr; 90 DATA_BLOB blob; 89 struct registry_key *key_hive, *key_eventlog, *key_source; 90 struct security_token *token = NULL; 91 const char *hive_name, *relpath; 92 enum winreg_CreateAction action; 93 struct registry_value *value; 94 static const uint32_t ACCESS = REG_KEY_READ | REG_KEY_WRITE; 95 bool ret = false; 91 96 92 97 if (!elogs) { 93 return False; 98 d_printf("No Eventlogs configured\n"); 99 goto done; 94 100 } 95 101 … … 102 108 d_printf("Eventlog [%s] not found in list of valid event logs\n", 103 109 eventlog); 104 return false; /* invalid named passed in */110 goto done; 105 111 } 106 112 … … 110 116 /* todo add to Sources */ 111 117 112 werr = regval_ctr_init(ctx, &values);113 if(!W_ERROR_IS_OK(werr)) {114 d_printf("talloc() failure!\n");115 return false;116 }117 118 118 evtlogpath = talloc_asprintf(ctx, "%s\\%s", KEY_EVENTLOG, eventlog); 119 119 if (!evtlogpath) { 120 TALLOC_FREE(values); 121 return false; 122 } 123 124 regdb_fetch_values( evtlogpath, values ); 125 126 127 if ( !( rval = regval_ctr_getvalue( values, "Sources" ) ) ) { 128 d_printf("No Sources value for [%s]!\n", eventlog); 129 return False; 120 d_printf("Out of memory\n"); 121 goto done; 122 } 123 124 relpath = evtlogpath + sizeof(KEY_EVENTLOG); 125 hive_name = talloc_strndup(ctx, evtlogpath, relpath - evtlogpath); 126 if (!hive_name) { 127 d_printf("Out of memory\n"); 128 goto done; 129 } 130 relpath++; 131 132 werr = ntstatus_to_werror(registry_create_admin_token(ctx, &token)); 133 if (!W_ERROR_IS_OK(werr)) { 134 d_printf("Failed to create admin token: %s\n", win_errstr(werr)); 135 goto done; 136 } 137 138 werr = reg_openhive(ctx, hive_name, ACCESS, token, &key_hive); 139 if (!W_ERROR_IS_OK(werr)) { 140 d_printf("Failed to open hive [%s]: %s\n", hive_name, win_errstr(werr)); 141 goto done; 142 } 143 144 werr = reg_openkey(ctx, key_hive, relpath, ACCESS, &key_eventlog); 145 if (!W_ERROR_IS_OK(werr)) { 146 d_printf("Failed to open key [%s]: %s\n", evtlogpath, win_errstr(werr)); 147 goto done; 148 } 149 150 werr = reg_queryvalue(ctx, key_eventlog, "Sources", &value); 151 if (!W_ERROR_IS_OK(werr)) { 152 d_printf("Failed to get value \"Sources\" for [%s]: %s\n", evtlogpath, win_errstr(werr)); 153 goto done; 130 154 } 131 155 /* perhaps this adding a new string to a multi_sz should be a fn? */ 132 156 /* check to see if it's there already */ 133 157 134 if ( regval_type(rval)!= REG_MULTI_SZ ) {135 d_printf("Wrong type for Sources, should be REG_MULTI_SZ\n");136 return False;158 if ( value->type != REG_MULTI_SZ ) { 159 d_printf("Wrong type for \"Sources\", should be REG_MULTI_SZ\n"); 160 goto done; 137 161 } 138 162 /* convert to a 'regulah' chars to do some comparisons */ 139 163 140 already_in = False;164 already_in = false; 141 165 wrklist = NULL; 142 dump_data(1, regval_data_p(rval), regval_size(rval));143 144 blob = data_blob_const(regval_data_p(rval), regval_size(rval));145 if (!pull_reg_multi_sz(talloc_tos(), &blob, &wrklist)) {146 return false;166 dump_data(1, value->data.data, value->data.length); 167 168 if (!pull_reg_multi_sz(ctx, &value->data, &wrklist)) { 169 d_printf("Failed to pull REG_MULTI_SZ from \"Sources\"\n"); 170 goto done; 147 171 } 148 172 … … 159 183 d_printf("Source name [%s] already in list for [%s] \n", 160 184 sourcename, eventlog); 161 already_in = True;185 already_in = true; 162 186 break; 163 187 } … … 168 192 } 169 193 170 wp = wrklist;171 172 194 if ( !already_in ) { 173 195 /* make a new list with an additional entry; copy values, add another */ 174 wp = TALLOC_ARRAY(ctx, const char *, numsources + 2 ); 175 196 wp = talloc_realloc(ctx, wrklist, const char *, numsources + 2 ); 176 197 if ( !wp ) { 177 d_printf("talloc() failed \n"); 178 return False; 179 } 180 memcpy( wp, wrklist, sizeof( char * ) * numsources ); 181 *( wp + numsources ) = ( char * ) sourcename; 182 *( wp + numsources + 1 ) = NULL; 183 if (!push_reg_multi_sz(ctx, &blob, wp)) { 184 return false; 185 } 186 dump_data( 1, blob.data, blob.length); 187 regval_ctr_addvalue( values, "Sources", REG_MULTI_SZ, 188 blob.data, blob.length); 189 regdb_store_values( evtlogpath, values ); 190 data_blob_free(&blob); 198 d_printf("Out of memory\n"); 199 goto done; 200 } 201 202 wp[numsources] = sourcename; 203 wp[numsources+1] = NULL; 204 if (!push_reg_multi_sz(ctx, &value->data, wp)) { 205 d_printf("Failed to push Sources\n"); 206 goto done; 207 } 208 dump_data( 1, value->data.data, value->data.length); 209 werr = reg_setvalue(key_eventlog, "Sources", value); 210 if (!W_ERROR_IS_OK(werr)) { 211 d_printf("Failed to set value Sources: %s\n", win_errstr(werr)); 212 goto done; 213 } 191 214 } else { 192 215 d_printf("Source name [%s] found in existing list of sources\n", 193 216 sourcename); 194 217 } 195 TALLOC_FREE(values); 196 TALLOC_FREE(wrklist); /* */ 197 198 werr = regsubkey_ctr_init(ctx, &subkeys); 199 if (!W_ERROR_IS_OK(werr)) { 200 d_printf("talloc() failure!\n"); 201 return False; 202 } 203 TALLOC_FREE(evtlogpath); 204 evtlogpath = talloc_asprintf(ctx, "%s\\%s", KEY_EVENTLOG, eventlog ); 205 if (!evtlogpath) { 206 TALLOC_FREE(subkeys); 207 return false; 208 } 209 210 regdb_fetch_keys( evtlogpath, subkeys ); 211 212 if ( !regsubkey_ctr_key_exists( subkeys, sourcename ) ) { 218 219 werr = reg_createkey(ctx, key_eventlog, sourcename, ACCESS, &key_source, &action); 220 if (!W_ERROR_IS_OK(werr)) { 221 d_printf("Failed to create subkey \"%s\" of \"%s\": %s\n", sourcename, evtlogpath, win_errstr(werr)); 222 goto done; 223 } 224 225 if (action == REG_CREATED_NEW_KEY) { 213 226 d_printf(" Source name [%s] for eventlog [%s] didn't exist, adding \n", 214 227 sourcename, eventlog); 215 regsubkey_ctr_addkey( subkeys, sourcename ); 216 if ( !regdb_store_keys( evtlogpath, subkeys ) ) 217 return False; 218 } 219 TALLOC_FREE(subkeys); 228 } 220 229 221 230 /* at this point KEY_EVENTLOG/<eventlog>/<sourcename> key is in there. Now need to add EventMessageFile */ 222 231 223 /* now allocate room for the source's subkeys */224 225 werr = regsubkey_ctr_init(ctx, &subkeys);226 if (!W_ERROR_IS_OK(werr)) {227 d_printf("talloc() failure!\n");228 return False;229 }230 TALLOC_FREE(evtlogpath);231 evtlogpath = talloc_asprintf(ctx, "%s\\%s\\%s",232 KEY_EVENTLOG, eventlog, sourcename);233 if (!evtlogpath) {234 TALLOC_FREE(subkeys);235 return false;236 }237 238 regdb_fetch_keys( evtlogpath, subkeys );239 240 232 /* now add the values to the KEY_EVENTLOG/Application form key */ 241 werr = regval_ctr_init(ctx, &values);242 if (!W_ERROR_IS_OK(werr)) {243 d_printf("talloc() failure!\n");244 return False;245 }246 233 d_printf("Storing EventMessageFile [%s] to eventlog path of [%s]\n", 247 234 messagefile, evtlogpath); 248 235 249 regdb_fetch_values( evtlogpath, values ); 250 251 regval_ctr_addvalue_sz(values, "EventMessageFile", messagefile); 252 regdb_store_values( evtlogpath, values ); 253 254 TALLOC_FREE(values); 255 256 return True; 236 if (!push_reg_sz(ctx, &value->data, messagefile)) { 237 d_printf("Failed to push \"EventMessageFile\"\n"); 238 goto done; 239 } 240 value->type = REG_SZ; 241 242 werr = reg_setvalue(key_source, "EventMessageFile", value); 243 if (!W_ERROR_IS_OK(werr)) { 244 d_printf("Failed to set value \"EventMessageFile\": %s\n", win_errstr(werr)); 245 return false; 246 } 247 ret = true; 248 done: 249 talloc_free(ctx); 250 return ret; 257 251 } 258 252 259 253 static int DoAddSourceCommand( int argc, char **argv, bool debugflag, char *exename ) 260 254 { 255 WERROR werr; 261 256 262 257 if ( argc < 3 ) { … … 265 260 return -1; 266 261 } 262 267 263 /* must open the registry before we access it */ 268 if (!W_ERROR_IS_OK(regdb_init())) { 269 printf( "Can't open the registry.\n" ); 270 return -1; 271 } 272 273 if ( !eventlog_add_source( argv[0], argv[1], argv[2] ) ) 264 werr = registry_init_common(); 265 if (!W_ERROR_IS_OK(werr)) { 266 printf("Can't open the registry: %s.\n", win_errstr(werr)); 267 return -1; 268 } 269 werr = regdb_transaction_start(); 270 if (!W_ERROR_IS_OK(werr)) { 271 printf("Can't start transaction on registry: %s.\n", win_errstr(werr)); 272 return -1; 273 } 274 275 if ( !eventlog_add_source( argv[0], argv[1], argv[2] ) ) { 276 regdb_transaction_cancel(); 274 277 return -2; 278 } 279 werr = regdb_transaction_commit(); 280 if (!W_ERROR_IS_OK(werr)) { 281 printf("Failed to commit transaction on registry: %s.\n", win_errstr(werr)); 282 return -1; 283 } 275 284 return 0; 276 285 } … … 366 375 ELOG_TDB *etdb; 367 376 TALLOC_CTX *mem_ctx = talloc_tos(); 368 const char *tdb_filename;369 377 uint32_t count = 1; 370 378 … … 372 380 return -1; 373 381 } 374 375 tdb_filename = argv[0];376 382 377 383 if (argc > 1) { … … 422 428 fstring opname; 423 429 424 load_case_tables();430 smb_init_locale(); 425 431 426 432 opt_debug = 0; /* todo set this from getopts */ … … 468 474 469 475 if ( configfile == NULL ) { 470 lp_load (get_dyn_CONFIGFILE(), True, False, False, True);471 } else if (!lp_load (configfile, True, False, False, True)) {476 lp_load_global(get_dyn_CONFIGFILE()); 477 } else if (!lp_load_global(configfile)) { 472 478 printf("Unable to parse configfile '%s'\n",configfile); 473 479 exit( 1 ); … … 476 482 /* note that the separate command types should call usage if they need to... */ 477 483 while ( 1 ) { 478 if ( ! StrCaseCmp( opname, "addsource" ) ) {484 if ( !strcasecmp_m( opname, "addsource" ) ) { 479 485 rc = DoAddSourceCommand( argc, argv, opt_debug, 480 486 exename ); 481 487 break; 482 488 } 483 if ( ! StrCaseCmp( opname, "write" ) ) {489 if ( !strcasecmp_m( opname, "write" ) ) { 484 490 rc = DoWriteCommand( argc, argv, opt_debug, exename ); 485 491 break; 486 492 } 487 if ( ! StrCaseCmp( opname, "dump" ) ) {493 if ( !strcasecmp_m( opname, "dump" ) ) { 488 494 rc = DoDumpCommand( argc, argv, opt_debug, exename ); 489 495 break;
Note:
See TracChangeset
for help on using the changeset viewer.