Ejemplo n.º 1
0
/**
 * smbconf initialization dispatcher
 *
 * this takes a configuration source in the form of
 * backend:path and calles the appropriate backend
 * init function with the path argument
 *
 * known backends:
 * -  "registry" or "reg"
 * -  "txt" or "file"
 */
WERROR smbconf_init(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
		    const char *source)
{
	WERROR werr;
	char *backend = NULL;
	char *path = NULL;
	char *sep;
	TALLOC_CTX *tmp_ctx = talloc_stackframe();

	if (conf_ctx == NULL) {
		werr = WERR_INVALID_PARAM;
		goto done;
	}

	if ((source == NULL) || (*source == '\0')) {
		werr = WERR_INVALID_PARAM;
		goto done;
	}

	backend = talloc_strdup(tmp_ctx, source);
	if (backend == NULL) {
		werr = WERR_NOMEM;
		goto done;
	}

	sep = strchr(backend, ':');
	if (sep != NULL) {
		*sep = '\0';
		path = sep + 1;
		if (strlen(path) == 0) {
			path = NULL;
		}
	}

	if (strequal(backend, "registry") || strequal(backend, "reg")) {
		werr = smbconf_init_reg(mem_ctx, conf_ctx, path);
	} else if (strequal(backend, "file") || strequal(backend, "txt")) {
		werr = smbconf_init_txt(mem_ctx, conf_ctx, path);
	} else if (sep == NULL) {
		/*
		 * If no separator was given in the source, and the string is
		 * not a known backend, assume file backend and use the source
		 * string as a path argument.
		 */
		werr = smbconf_init_txt(mem_ctx, conf_ctx, backend);
	} else {
		/*
		 * Separator was specified but this is not a known backend.
		 * As a last resort, try to interpret the original source
		 * string as a file name that contains a ":" sign.
		 * This may occur with an include directive like this:
		 * 'include = /path/to/file.%T'
		 */
		werr = smbconf_init_txt(mem_ctx, conf_ctx, source);
	}

done:
	talloc_free(tmp_ctx);
	return werr;
}
Ejemplo n.º 2
0
static bool torture_smbconf_reg(void)
{
	sbcErr err;
	bool ret = true;
	struct smbconf_ctx *conf_ctx = NULL;
	TALLOC_CTX *mem_ctx = talloc_stackframe();

	printf("test: registry backend\n");

	printf("TEST: init\n");
	err = smbconf_init_reg(mem_ctx, &conf_ctx, NULL);
	if (!SBC_ERROR_IS_OK(err)) {
		printf("FAIL: init failed: %s\n", sbcErrorString(err));
		ret = false;
		goto done;
	}
	printf("OK: init\n");

	ret &= test_get_includes(conf_ctx);
	ret &= test_set_get_includes(conf_ctx);
	ret &= test_delete_includes(conf_ctx);

	smbconf_shutdown(conf_ctx);

done:
	printf("%s: registry backend\n", ret ? "success" : "failure");
	talloc_free(mem_ctx);
	return ret;
}
Ejemplo n.º 3
0
static bool torture_smbconf_reg(void)
{
	WERROR werr;
	bool ret = true;
	struct smbconf_ctx *conf_ctx = NULL;
	TALLOC_CTX *mem_ctx = talloc_stackframe();

	printf("test: registry backend\n");

	printf("test: init\n");
	werr = smbconf_init_reg(mem_ctx, &conf_ctx, NULL);
	if (!W_ERROR_IS_OK(werr)) {
		printf("failure: init failed: %s\n", dos_errstr(werr));
		ret = false;
		goto done;
	}
	printf("success: init\n");

	ret &= test_get_includes(conf_ctx);
	ret &= test_set_get_includes(conf_ctx);
	ret &= test_delete_includes(conf_ctx);

	smbconf_shutdown(conf_ctx);

	printf("%s: registry backend\n", ret ? "success" : "failure");

done:
	TALLOC_FREE(mem_ctx);
	return ret;
}
Ejemplo n.º 4
0
/**
 * smbconf initialization dispatcher
 *
 * this takes a configuration source in the form of
 * backend:path and calles the appropriate backend
 * init function with the path argument
 *
 * known backends:
 * -  "registry" or "reg"
 * -  "txt" or "file"
 */
WERROR smbconf_init(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
		    const char *source)
{
	WERROR werr;
	char *backend = NULL;
	char *path = NULL;
	char *sep;
	TALLOC_CTX *tmp_ctx = talloc_stackframe();

	if (conf_ctx == NULL) {
		werr = WERR_INVALID_PARAM;
		goto done;
	}

	if ((source == NULL) || (*source == '\0')) {
		werr = WERR_INVALID_PARAM;
		goto done;
	}

	backend = talloc_strdup(tmp_ctx, source);
	if (backend == NULL) {
		werr = WERR_NOMEM;
		goto done;
	}

	sep = strchr(backend, ':');
	if (sep != NULL) {
		*sep = '\0';
		path = sep + 1;
		if (strlen(path) == 0) {
			path = NULL;
		}
	}

	if (strequal(backend, "registry") || strequal(backend, "reg")) {
		werr = smbconf_init_reg(mem_ctx, conf_ctx, path);
	} else if (strequal(backend, "file") || strequal(backend, "txt")) {
		werr = smbconf_init_txt(mem_ctx, conf_ctx, path);
	} else if (sep == NULL) {
		/*
		 * If no separator was given in the source, and the string is
		 * not a know backend, assume file backend and use the source
		 * string as a path argument.
		 */
		werr = smbconf_init_txt(mem_ctx, conf_ctx, backend);
	} else {
		/*
		 * Separator was specified but this is not a known backend.
		 * Can't handle this.
		 */
		DEBUG(1, ("smbconf_init: ERROR - unknown backend '%s' given\n",
			  backend));
		werr = WERR_INVALID_PARAM;
	}

done:
	TALLOC_FREE(tmp_ctx);
	return werr;
}
Ejemplo n.º 5
0
static WERROR NetServerSetInfo_l_1005(struct libnetapi_ctx *ctx,
				      struct NetServerSetInfo *r)
{
	WERROR werr = WERR_OK;
	sbcErr err;
	struct smbconf_ctx *conf_ctx;
	struct srvsvc_NetSrvInfo1005 *info1005;

	if (!r->in.buffer) {
		*r->out.parm_error = 1005; /* sure here ? */
		return WERR_INVALID_PARAM;
	}

	info1005 = (struct srvsvc_NetSrvInfo1005 *)r->in.buffer;

	if (!info1005->comment) {
		*r->out.parm_error = 1005;
		return WERR_INVALID_PARAM;
	}

#ifdef REGISTRY_BACKEND
	if (!lp_config_backend_is_registry())
#endif
	{
		libnetapi_set_error_string(ctx,
			"Configuration manipulation requested but not "
			"supported by backend");
		return WERR_NOT_SUPPORTED;
	}

	err = smbconf_init_reg(ctx, &conf_ctx, NULL);
	if (!SBC_ERROR_IS_OK(err)) {
		libnetapi_set_error_string(ctx,
			"Could not initialize backend: %s",
			sbcErrorString(err));
		werr = WERR_NO_SUCH_SERVICE;
		goto done;
	}

	err = smbconf_set_global_parameter(conf_ctx, "server string",
					    info1005->comment);
	if (!SBC_ERROR_IS_OK(err)) {
		libnetapi_set_error_string(ctx,
			"Could not set global parameter: %s",
			sbcErrorString(err));
		werr = WERR_NO_SUCH_SERVICE;
		goto done;
	}

 done:
	smbconf_shutdown(conf_ctx);
	return werr;
}
Ejemplo n.º 6
0
static WERROR NetServerSetInfo_l_1005(struct libnetapi_ctx *ctx,
				      struct NetServerSetInfo *r)
{
	WERROR werr;
	struct smbconf_ctx *conf_ctx;
	struct srvsvc_NetSrvInfo1005 *info1005;

	if (!r->in.buffer) {
		*r->out.parm_error = 1005; /* sure here ? */
		return WERR_INVALID_PARAM;
	}

	info1005 = (struct srvsvc_NetSrvInfo1005 *)r->in.buffer;

	if (!info1005->comment) {
		*r->out.parm_error = 1005;
		return WERR_INVALID_PARAM;
	}

	if (!lp_config_backend_is_registry()) {
		libnetapi_set_error_string(ctx,
			"Configuration manipulation requested but not "
			"supported by backend");
		return WERR_NOT_SUPPORTED;
	}

	werr = smbconf_init_reg(ctx, &conf_ctx, NULL);
	if (!W_ERROR_IS_OK(werr)) {
		goto done;
	}

	werr = smbconf_set_global_parameter(conf_ctx, "server string",
					    info1005->comment);

 done:
	smbconf_shutdown(conf_ctx);
	return werr;
}
Ejemplo n.º 7
0
#ifdef REGISTRY_BACKEND
if (strequal(backend, "registry") || strequal(backend, "reg")) {
		err = smbconf_init_reg(mem_ctx, conf_ctx, path);
	} else
#endif
	if (strequal(backend, "file") || strequal(backend, "txt")) {
		err = smbconf_init_txt(mem_ctx, conf_ctx, path);
	} else if (sep == NULL) {
		/*
		 * If no separator was given in the source, and the string is
		 * not a known backend, assume file backend and use the source
		 * string as a path argument.
		 */
		err = smbconf_init_txt(mem_ctx, conf_ctx, backend);
	} else {
		/*
		 * Separator was specified but this is not a known backend.
		 * As a last resort, try to interpret the original source
		 * string as a file name that contains a ":" sign.
		 * This may occur with an include directive like this:
		 * 'include = /path/to/file.%T'
		 */
		err = smbconf_init_txt(mem_ctx, conf_ctx, source);
	}