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; }
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; }
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; }
static bool torture_smbconf_txt(void) { sbcErr err; bool ret = true; const char *filename = "/tmp/smb.conf.smbconf_testsuite"; struct smbconf_ctx *conf_ctx = NULL; TALLOC_CTX *mem_ctx = talloc_stackframe(); printf("test: text backend\n"); if (!create_conf_file(filename)) { ret = false; goto done; } printf("TEST: init\n"); err = smbconf_init_txt(mem_ctx, &conf_ctx, filename); if (!SBC_ERROR_IS_OK(err)) { printf("FAIL: text backend failed: %s\n", sbcErrorString(err)); ret = false; goto done; } printf("OK: init\n"); ret &= test_get_includes(conf_ctx); smbconf_shutdown(conf_ctx); printf("TEST: unlink file\n"); if (unlink(filename) != 0) { printf("OK: unlink failed: %s\n", strerror(errno)); ret = false; goto done; } printf("OK: unlink file\n"); done: printf("%s: text backend\n", ret ? "success" : "failure"); talloc_free(mem_ctx); return ret; }
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; }
/** * Wrapper function to call the main conf functions. * The wrapper calls handles opening and closing of the * configuration. */ static int net_conf_wrap_function(struct net_context *c, int (*fn)(struct net_context *, struct smbconf_ctx *, int, const char **), int argc, const char **argv) { sbcErr err; TALLOC_CTX *mem_ctx = talloc_stackframe(); struct smbconf_ctx *conf_ctx; int ret = -1; err = smbconf_init(mem_ctx, &conf_ctx, "registry:"); if (!SBC_ERROR_IS_OK(err)) { talloc_free(mem_ctx); return -1; } ret = fn(c, conf_ctx, argc, argv); smbconf_shutdown(conf_ctx); talloc_free(mem_ctx); return ret; }