void load_registry_shares(void) { struct registry_key *key; char *name; WERROR err; int i; DEBUG(8, ("load_registry_shares()\n")); if (!lp_registry_shares()) { return; } err = reg_open_path(NULL, KEY_SMBCONF, REG_KEY_READ, get_root_nt_token(), &key); if (!(W_ERROR_IS_OK(err))) { return; } for (i=0; W_ERROR_IS_OK(reg_enumkey(key, key, i, &name, NULL)); i++) { load_registry_service(name); TALLOC_FREE(name); } TALLOC_FREE(key); return; }
WERROR gp_init_reg_ctx(TALLOC_CTX *mem_ctx, const char *initial_path, uint32_t desired_access, const struct security_token *token, struct gp_registry_context **reg_ctx) { struct gp_registry_context *tmp_ctx; WERROR werr; if (!reg_ctx) { return WERR_INVALID_PARAM; } werr = registry_init_basic(); if (!W_ERROR_IS_OK(werr)) { return werr; } tmp_ctx = talloc_zero(mem_ctx, struct gp_registry_context); W_ERROR_HAVE_NO_MEMORY(tmp_ctx); if (token) { tmp_ctx->token = token; } else { tmp_ctx->token = registry_create_system_token(mem_ctx); } if (!tmp_ctx->token) { TALLOC_FREE(tmp_ctx); return WERR_NOMEM; } werr = regdb_open(); if (!W_ERROR_IS_OK(werr)) { return werr; } if (initial_path) { tmp_ctx->path = talloc_strdup(mem_ctx, initial_path); if (!tmp_ctx->path) { TALLOC_FREE(tmp_ctx); return WERR_NOMEM; } werr = reg_open_path(mem_ctx, tmp_ctx->path, desired_access, tmp_ctx->token, &tmp_ctx->curr_key); if (!W_ERROR_IS_OK(werr)) { TALLOC_FREE(tmp_ctx); return werr; } } *reg_ctx = tmp_ctx; return WERR_OK; }
/** * Drop the whole configuration (restarting empty) - registry version */ static sbcErr smbconf_reg_drop(struct smbconf_ctx *ctx) { char *path, *p; WERROR werr = WERR_OK; sbcErr err = SBC_ERR_OK; struct registry_key *parent_key = NULL; struct registry_key *new_key = NULL; TALLOC_CTX* mem_ctx = talloc_stackframe(); enum winreg_CreateAction action; struct security_token *token; werr = ntstatus_to_werror(registry_create_admin_token(ctx, &token)); if (!W_ERROR_IS_OK(werr)) { DEBUG(1, ("Error creating admin token\n")); err = SBC_ERR_UNKNOWN_FAILURE; goto done; } path = talloc_strdup(mem_ctx, ctx->path); if (path == NULL) { err = SBC_ERR_NOMEM; goto done; } p = strrchr(path, '\\'); if (p == NULL) { err = SBC_ERR_INVALID_PARAM; goto done; } *p = '\0'; werr = reg_open_path(mem_ctx, path, REG_KEY_WRITE, token, &parent_key); if (!W_ERROR_IS_OK(werr)) { err = SBC_ERR_IO_FAILURE; goto done; } werr = reg_deletesubkeys_recursive(parent_key, p+1); if (!W_ERROR_IS_OK(werr)) { err = SBC_ERR_IO_FAILURE; goto done; } werr = reg_createkey(mem_ctx, parent_key, p+1, REG_KEY_WRITE, &new_key, &action); if (!W_ERROR_IS_OK(werr)) { err = SBC_ERR_IO_FAILURE; goto done; } done: talloc_free(mem_ctx); return err; }
/** * initialize the registry smbconf backend */ static sbcErr smbconf_reg_init(struct smbconf_ctx *ctx, const char *path) { WERROR werr = WERR_OK; sbcErr err; struct security_token *token; if (path == NULL) { path = KEY_SMBCONF; } ctx->path = talloc_strdup(ctx, path); if (ctx->path == NULL) { err = SBC_ERR_NOMEM; goto done; } ctx->data = talloc_zero(ctx, struct reg_private_data); werr = ntstatus_to_werror(registry_create_admin_token(ctx, &token)); if (!W_ERROR_IS_OK(werr)) { DEBUG(1, ("Error creating admin token\n")); err = SBC_ERR_UNKNOWN_FAILURE; goto done; } rpd(ctx)->open = false; werr = registry_init_smbconf(path); if (!W_ERROR_IS_OK(werr)) { err = SBC_ERR_BADFILE; goto done; } err = ctx->ops->open_conf(ctx); if (!SBC_ERROR_IS_OK(err)) { DEBUG(1, ("Error opening the registry.\n")); goto done; } werr = reg_open_path(ctx, ctx->path, KEY_ENUMERATE_SUB_KEYS | REG_KEY_WRITE, token, &rpd(ctx)->base_key); if (!W_ERROR_IS_OK(werr)) { err = SBC_ERR_UNKNOWN_FAILURE; goto done; } done: return err; }
/** * legacy open key function that should be replaced by uses of * reg_open_path */ WERROR regkey_open_internal( TALLOC_CTX *ctx, REGISTRY_KEY **regkey, const char *path, const struct nt_user_token *token, uint32 access_desired ) { struct registry_key *key; WERROR err; err = reg_open_path(NULL, path, access_desired, token, &key); if (!W_ERROR_IS_OK(err)) { return err; } *regkey = talloc_move(ctx, &key->key); TALLOC_FREE(key); return WERR_OK; }
WERROR gp_read_reg_subkey(TALLOC_CTX *mem_ctx, struct gp_registry_context *reg_ctx, const char *subkeyname, struct registry_key **key) { const char *tmp = NULL; if (!reg_ctx || !subkeyname || !key) { return WERR_INVALID_PARAM; } tmp = talloc_asprintf(mem_ctx, "%s\\%s", reg_ctx->path, subkeyname); W_ERROR_HAVE_NO_MEMORY(tmp); return reg_open_path(mem_ctx, tmp, REG_KEY_READ, reg_ctx->token, key); }
static int load_registry_service(const char *servicename) { struct registry_key *key; char *path; WERROR err; uint32 i; char *value_name; struct registry_value *value; int res = -1; if (!lp_registry_shares()) { return -1; } if ((servicename == NULL) || (*servicename == '\0')) { return -1; } if (strequal(servicename, GLOBAL_NAME)) { return -2; } if (asprintf(&path, "%s\\%s", KEY_SMBCONF, servicename) == -1) { return -1; } err = reg_open_path(NULL, path, REG_KEY_READ, get_root_nt_token(), &key); SAFE_FREE(path); if (!W_ERROR_IS_OK(err)) { return -1; } res = lp_add_service(servicename, -1); if (res == -1) { goto error; } for (i=0; W_ERROR_IS_OK(reg_enumvalue(key, key, i, &value_name, &value)); i++) { switch (value->type) { case REG_DWORD: { char *tmp; if (asprintf(&tmp, "%d", value->v.dword) == -1) { continue; } lp_do_parameter(res, value_name, tmp); SAFE_FREE(tmp); break; } case REG_SZ: { lp_do_parameter(res, value_name, value->v.sz.str); break; } default: /* Ignore all the rest */ break; } TALLOC_FREE(value_name); TALLOC_FREE(value); } error: TALLOC_FREE(key); return res; }
static bool sync_eventlog_params( EVENTLOG_INFO *info ) { char *path = NULL; uint32 uiMaxSize; uint32 uiRetention; struct registry_key *key; struct registry_value *value; WERROR wresult; char *elogname = info->logname; TALLOC_CTX *ctx = talloc_stackframe(); bool ret = false; DEBUG( 4, ( "sync_eventlog_params with %s\n", elogname ) ); if ( !info->etdb ) { DEBUG( 4, ( "No open tdb! (%s)\n", info->logname ) ); goto done; } /* set resonable defaults. 512Kb on size and 1 week on time */ uiMaxSize = 0x80000; uiRetention = 604800; /* the general idea is to internally open the registry key and retrieve the values. That way we can continue to use the same fetch/store api that we use in srv_reg_nt.c */ path = talloc_asprintf(ctx, "%s/%s", KEY_EVENTLOG, elogname ); if (!path) { goto done; } wresult = reg_open_path(ctx, path, REG_KEY_READ, get_root_nt_token(), &key); if ( !W_ERROR_IS_OK( wresult ) ) { DEBUG( 4, ( "sync_eventlog_params: Failed to open key [%s] (%s)\n", path, win_errstr( wresult ) ) ); goto done; } wresult = reg_queryvalue(key, key, "Retention", &value); if (!W_ERROR_IS_OK(wresult)) { DEBUG(4, ("Failed to query value \"Retention\": %s\n", win_errstr(wresult))); goto done; } uiRetention = value->v.dword; wresult = reg_queryvalue(key, key, "MaxSize", &value); if (!W_ERROR_IS_OK(wresult)) { DEBUG(4, ("Failed to query value \"MaxSize\": %s\n", win_errstr(wresult))); goto done; } uiMaxSize = value->v.dword; tdb_store_int32( ELOG_TDB_CTX(info->etdb), EVT_MAXSIZE, uiMaxSize ); tdb_store_int32( ELOG_TDB_CTX(info->etdb), EVT_RETENTION, uiRetention ); ret = true; done: TALLOC_FREE(ctx); return ret; }