libgpo: remove some unused code and remove that important FIXME note.
[metze/samba/wip.git] / libgpo / gpo_ini.c
index a4bff0e86b8381412bfc3980163248065c9ba99e..a91bb9217ca0ffd407e6c0c9882c2b8f5d801cc3 100644 (file)
@@ -32,6 +32,9 @@ static bool change_section(const char *section, void *ctx_ptr)
                talloc_free(ctx->current_section);
        }
        ctx->current_section = talloc_strdup(ctx, section);
+       if (!ctx->current_section) {
+               return false;
+       }
        return true;
 }
 
@@ -41,10 +44,25 @@ static bool change_section(const char *section, void *ctx_ptr)
 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;
 }
@@ -63,6 +81,7 @@ static NTSTATUS convert_file_from_ucs2(TALLOC_CTX *mem_ctx,
        NTSTATUS status;
        size_t n = 0;
        size_t converted_size;
+       mode_t mask;
 
        if (!filename_out) {
                return NT_STATUS_INVALID_PARAMETER;
@@ -81,7 +100,9 @@ static NTSTATUS convert_file_from_ucs2(TALLOC_CTX *mem_ctx,
                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;
@@ -108,7 +129,7 @@ static NTSTATUS convert_file_from_ucs2(TALLOC_CTX *mem_ctx,
        }
 
        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;
        }
 
@@ -135,7 +156,9 @@ NTSTATUS gp_inifile_getstring(struct gp_inifile_context *ctx, const char *key, c
 
        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;
                }
        }
@@ -155,13 +178,43 @@ NTSTATUS gp_inifile_getint(struct gp_inifile_context *ctx, const char *key, int
                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,