talloc_free(ctx->current_section);
}
ctx->current_section = talloc_strdup(ctx, section);
+ if (!ctx->current_section) {
+ return false;
+ }
return true;
}
static bool store_keyval_pair(const char *key, const char *value, void *ctx_ptr)
{
struct gp_inifile_context *ctx = (struct gp_inifile_context *) ctx_ptr;
+
ctx->data = talloc_realloc(ctx, ctx->data, struct keyval_pair *, ctx->keyval_count+1);
+ if (!ctx->data) {
+ return false;
+ }
+
ctx->data[ctx->keyval_count] = talloc_zero(ctx, struct keyval_pair);
+ if (!ctx->data[ctx->keyval_count]) {
+ return false;
+ }
+
ctx->data[ctx->keyval_count]->key = talloc_asprintf(ctx, "%s:%s", ctx->current_section, key);
ctx->data[ctx->keyval_count]->val = talloc_strdup(ctx, value);
+
+ if (!ctx->data[ctx->keyval_count]->key ||
+ !ctx->data[ctx->keyval_count]->val) {
+ return false;
+ }
+
ctx->keyval_count++;
return true;
}
NTSTATUS status;
size_t n = 0;
size_t converted_size;
+ mode_t mask;
if (!filename_out) {
return NT_STATUS_INVALID_PARAMETER;
goto out;
}
+ mask = umask(S_IRWXO | S_IRWXG);
tmp_fd = mkstemp(tmp_name);
+ umask(mask);
if (tmp_fd == -1) {
status = NT_STATUS_ACCESS_DENIED;
goto out;
}
if (!convert_string_talloc(mem_ctx, CH_UTF16LE, CH_UNIX, data_in, n,
- (void *)&data_out, &converted_size, false))
+ (void *)&data_out, &converted_size))
{
status = NT_STATUS_INVALID_BUFFER_SIZE;
goto out;
}
if (write(tmp_fd, data_out, converted_size) != converted_size) {
- status = map_nt_error_from_unix(errno);
+ status = map_nt_error_from_unix_common(errno);
goto out;
}
for (i = 0; i < ctx->keyval_count; i++) {
if (strcmp(ctx->data[i]->key, key) == 0) {
- *ret = ctx->data[i]->val;
+ if (ret) {
+ *ret = ctx->data[i]->val;
+ }
return NT_STATUS_OK;
}
}
return result;
}
- *ret = (int)strtol(value, NULL, 10);
+ if (ret) {
+ *ret = (int)strtol(value, NULL, 10);
+ }
return NT_STATUS_OK;
}
/****************************************************************
****************************************************************/
+NTSTATUS gp_inifile_getbool(struct gp_inifile_context *ctx, const char *key, bool *ret)
+{
+ char *value;
+ NTSTATUS result;
+
+ result = gp_inifile_getstring(ctx,key, &value);
+ if (!NT_STATUS_IS_OK(result)) {
+ return result;
+ }
+
+ if (strequal(value, "Yes")) {
+ if (ret) {
+ *ret = true;
+ }
+ return NT_STATUS_OK;
+ } else if (strequal(value, "No")) {
+ if (ret) {
+ *ret = false;
+ }
+ return NT_STATUS_OK;
+ }
+
+ return NT_STATUS_NOT_FOUND;
+}
+
+/****************************************************************
+****************************************************************/
+
NTSTATUS gp_inifile_init_context(TALLOC_CTX *mem_ctx,
uint32_t flags,
const char *unix_path,