static sbcErr smbconf_reg_set_multi_sz_value(struct registry_key *key, const char *valname, const uint32_t num_strings, const char **strings) { WERROR werr; sbcErr err = SBC_ERR_OK; struct registry_value *value; uint32_t count; TALLOC_CTX *tmp_ctx = talloc_stackframe(); const char **array; if (strings == NULL) { err = SBC_ERR_INVALID_PARAM; goto done; } array = talloc_zero_array(tmp_ctx, const char *, num_strings + 1); if (array == NULL) { err = SBC_ERR_NOMEM; goto done; } value = talloc_zero(tmp_ctx, struct registry_value); if (value == NULL) { err = SBC_ERR_NOMEM; goto done; } value->type = REG_MULTI_SZ; for (count = 0; count < num_strings; count++) { array[count] = talloc_strdup(value, strings[count]); if (array[count] == NULL) { err = SBC_ERR_NOMEM; goto done; } } if (!push_reg_multi_sz(value, &value->data, array)) { err = SBC_ERR_NOMEM; goto done; } werr = reg_setvalue(key, valname, value); if (!W_ERROR_IS_OK(werr)) { DEBUG(5, ("Error adding value '%s' to key '%s': %s\n", valname, key->key->name, win_errstr(werr))); err = SBC_ERR_ACCESS_DENIED; } done: talloc_free(tmp_ctx); return err; }
static WERROR gp_store_reg_val_dword(TALLOC_CTX *mem_ctx, struct registry_key *key, const char *val_name, uint32_t val) { struct registry_value reg_val; reg_val.type = REG_DWORD; reg_val.data = data_blob_talloc(mem_ctx, NULL, 4); SIVAL(reg_val.data.data, 0, val); return reg_setvalue(key, val_name, ®_val); }
static WERROR gp_store_reg_val_dword(TALLOC_CTX *mem_ctx, struct registry_key *key, const char *val_name, uint32_t val) { struct registry_value reg_val; ZERO_STRUCT(reg_val); reg_val.type = REG_DWORD; reg_val.v.dword = val; return reg_setvalue(key, val_name, ®_val); }
WERROR gp_store_reg_val_sz(TALLOC_CTX *mem_ctx, struct registry_key *key, const char *val_name, const char *val) { struct registry_value reg_val; reg_val.type = REG_SZ; if (!push_reg_sz(mem_ctx, ®_val.data, val)) { return WERR_NOMEM; } return reg_setvalue(key, val_name, ®_val); }
WERROR gp_store_reg_val_sz(TALLOC_CTX *mem_ctx, struct registry_key *key, const char *val_name, const char *val) { struct registry_value reg_val; ZERO_STRUCT(reg_val); /* FIXME: hack */ val = val ? val : " "; reg_val.type = REG_SZ; reg_val.v.sz.len = strlen(val); reg_val.v.sz.str = talloc_strdup(mem_ctx, val); W_ERROR_HAVE_NO_MEMORY(reg_val.v.sz.str); return reg_setvalue(key, val_name, ®_val); }
/** * add a value to a key. */ static sbcErr smbconf_reg_set_value(struct registry_key *key, const char *valname, const char *valstr) { struct registry_value val; WERROR werr = WERR_OK; sbcErr err; char *subkeyname; const char *canon_valname; const char *canon_valstr; if (!lp_canonicalize_parameter_with_value(valname, valstr, &canon_valname, &canon_valstr)) { if (canon_valname == NULL) { DEBUG(5, ("invalid parameter '%s' given\n", valname)); } else { DEBUG(5, ("invalid value '%s' given for " "parameter '%s'\n", valstr, valname)); } err = SBC_ERR_INVALID_PARAM; goto done; } if (smbconf_reg_valname_forbidden(canon_valname)) { DEBUG(5, ("Parameter '%s' not allowed in registry.\n", canon_valname)); err = SBC_ERR_INVALID_PARAM; goto done; } subkeyname = strrchr_m(key->key->name, '\\'); if ((subkeyname == NULL) || (*(subkeyname +1) == '\0')) { DEBUG(5, ("Invalid registry key '%s' given as " "smbconf section.\n", key->key->name)); err = SBC_ERR_INVALID_PARAM; goto done; } subkeyname++; if (!strequal(subkeyname, GLOBAL_NAME) && lp_parameter_is_global(valname)) { DEBUG(5, ("Global parameter '%s' not allowed in " "service definition ('%s').\n", canon_valname, subkeyname)); err = SBC_ERR_INVALID_PARAM; goto done; } ZERO_STRUCT(val); val.type = REG_SZ; if (!push_reg_sz(talloc_tos(), &val.data, canon_valstr)) { err = SBC_ERR_NOMEM; goto done; } werr = reg_setvalue(key, canon_valname, &val); if (!W_ERROR_IS_OK(werr)) { DEBUG(5, ("Error adding value '%s' to " "key '%s': %s\n", canon_valname, key->key->name, win_errstr(werr))); err = SBC_ERR_NOMEM; goto done; } err = SBC_ERR_OK; done: return err; }
/********************************************************************* for an eventlog, add in a source name. If the eventlog doesn't exist (not in the list) do nothing. If a source for the log already exists, change the information (remove, replace) *********************************************************************/ static bool eventlog_add_source( const char *eventlog, const char *sourcename, const char *messagefile ) { /* Find all of the eventlogs, add keys for each of them */ /* need to add to the value KEY_EVENTLOG/<eventlog>/Sources string (Creating if necessary) need to add KEY of source to KEY_EVENTLOG/<eventlog>/<source> */ const char **elogs = lp_eventlog_list( ); const char **wrklist, **wp; char *evtlogpath = NULL; int ii = 0; bool already_in; int i; int numsources = 0; TALLOC_CTX *ctx = talloc_stackframe(); WERROR werr; struct registry_key *key_hive, *key_eventlog, *key_source; struct security_token *token = NULL; const char *hive_name, *relpath; enum winreg_CreateAction action; struct registry_value *value; static const uint32_t ACCESS = REG_KEY_READ | REG_KEY_WRITE; bool ret = false; if (!elogs) { d_printf("No Eventlogs configured\n"); goto done; } for ( i = 0; elogs[i]; i++ ) { if ( strequal( elogs[i], eventlog ) ) break; } if ( !elogs[i] ) { d_printf("Eventlog [%s] not found in list of valid event logs\n", eventlog); goto done; } /* have to assume that the evenlog key itself exists at this point */ /* add in a key of [sourcename] under the eventlog key */ /* todo add to Sources */ evtlogpath = talloc_asprintf(ctx, "%s\\%s", KEY_EVENTLOG, eventlog); if (!evtlogpath) { d_printf("Out of memory\n"); goto done; } relpath = evtlogpath + sizeof(KEY_EVENTLOG); hive_name = talloc_strndup(ctx, evtlogpath, relpath - evtlogpath); if (!hive_name) { d_printf("Out of memory\n"); goto done; } relpath++; werr = ntstatus_to_werror(registry_create_admin_token(ctx, &token)); if (!W_ERROR_IS_OK(werr)) { d_printf("Failed to create admin token: %s\n", win_errstr(werr)); goto done; } werr = reg_openhive(ctx, hive_name, ACCESS, token, &key_hive); if (!W_ERROR_IS_OK(werr)) { d_printf("Failed to open hive [%s]: %s\n", hive_name, win_errstr(werr)); goto done; } werr = reg_openkey(ctx, key_hive, relpath, ACCESS, &key_eventlog); if (!W_ERROR_IS_OK(werr)) { d_printf("Failed to open key [%s]: %s\n", evtlogpath, win_errstr(werr)); goto done; } werr = reg_queryvalue(ctx, key_eventlog, "Sources", &value); if (!W_ERROR_IS_OK(werr)) { d_printf("Failed to get value \"Sources\" for [%s]: %s\n", evtlogpath, win_errstr(werr)); goto done; } /* perhaps this adding a new string to a multi_sz should be a fn? */ /* check to see if it's there already */ if ( value->type != REG_MULTI_SZ ) { d_printf("Wrong type for \"Sources\", should be REG_MULTI_SZ\n"); goto done; } /* convert to a 'regulah' chars to do some comparisons */ already_in = false; wrklist = NULL; dump_data(1, value->data.data, value->data.length); if (!pull_reg_multi_sz(ctx, &value->data, &wrklist)) { d_printf("Failed to pull REG_MULTI_SZ from \"Sources\"\n"); goto done; } for (ii=0; wrklist[ii]; ii++) { numsources++; } if (numsources > 0) { /* see if it's in there already */ wp = wrklist; while (wp && *wp ) { if ( strequal( *wp, sourcename ) ) { d_printf("Source name [%s] already in list for [%s] \n", sourcename, eventlog); already_in = true; break; } wp++; } } else { d_printf("Nothing in the sources list, this might be a problem\n"); } if ( !already_in ) { /* make a new list with an additional entry; copy values, add another */ wp = talloc_realloc(ctx, wrklist, const char *, numsources + 2 ); if ( !wp ) { d_printf("Out of memory\n"); goto done; } wp[numsources] = sourcename; wp[numsources+1] = NULL; if (!push_reg_multi_sz(ctx, &value->data, wp)) { d_printf("Failed to push Sources\n"); goto done; } dump_data( 1, value->data.data, value->data.length); werr = reg_setvalue(key_eventlog, "Sources", value); if (!W_ERROR_IS_OK(werr)) { d_printf("Failed to set value Sources: %s\n", win_errstr(werr)); goto done; } } else {