/** * 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; }
/** * 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; }
static bool torture_smbconf_txt(void) { WERROR werr; bool ret = true; struct smbconf_ctx *conf_ctx = NULL; TALLOC_CTX *mem_ctx = talloc_stackframe(); printf("test: text backend\n"); printf("test: init\n"); werr = smbconf_init_txt(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); smbconf_shutdown(conf_ctx); printf("%s: text backend\n", ret ? "success" : "failure"); done: TALLOC_FREE(mem_ctx); return ret; }
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; }