2 Unix SMB/CIFS implementation.
4 Copyright (C) Jelmer Vernooij 2004.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "lib/registry/common/registry.h"
24 static WERROR reg_dir_add_key(REG_KEY *parent, const char *name, uint32 access_mask, SEC_DESC *desc)
28 asprintf(&path, "%s%s\\%s", parent->handle->location, reg_key_get_path(parent), name);
29 path = reg_path_win2unix(path);
30 ret = mkdir(path, 0700);
32 if(ret == 0)return WERR_OK;
33 return WERR_INVALID_PARAM;
36 static WERROR reg_dir_del_key(REG_KEY *k)
38 return (rmdir((char *)k->backend_data) == 0)?WERR_OK:WERR_GENERAL_FAILURE;
41 static WERROR reg_dir_open_key(REG_HANDLE *h, const char *name, REG_KEY **subkey)
46 TALLOC_CTX *mem_ctx = talloc_init("tmp");
48 DEBUG(0, ("NULL pointer passed as directory name!"));
49 return WERR_INVALID_PARAM;
51 fullpath = talloc_asprintf(mem_ctx, "%s%s", h->location, name);
52 fullpath = reg_path_win2unix(fullpath);
54 d = opendir(fullpath);
56 DEBUG(3,("Unable to open '%s': %s\n", fullpath, strerror(errno)));
57 talloc_destroy(mem_ctx);
61 ret = reg_key_new_abs(name, h, fullpath);
62 talloc_steal(mem_ctx, ret->mem_ctx, fullpath);
63 talloc_destroy(mem_ctx);
68 static WERROR reg_dir_fetch_subkeys(REG_KEY *k, int *count, REG_KEY ***r)
72 char *fullpath = k->backend_data;
76 ar = talloc(k->mem_ctx, sizeof(REG_KEY *) * max);
78 d = opendir(fullpath);
80 if(!d) return WERR_INVALID_PARAM;
82 while((e = readdir(d))) {
83 if(e->d_type == DT_DIR &&
84 strcmp(e->d_name, ".") &&
85 strcmp(e->d_name, "..")) {
87 ar[(*count)] = reg_key_new_rel(e->d_name, k, NULL);
88 ar[(*count)]->backend_data = talloc_asprintf(ar[*count]->mem_ctx, "%s/%s", fullpath, e->d_name);
89 if(ar[(*count)])(*count)++;
93 ar = realloc(ar, sizeof(REG_KEY *) * max);
104 static WERROR reg_dir_open(REG_HANDLE *h, const char *loc, const char *credentials) {
105 if(!loc) return WERR_INVALID_PARAM;
109 static WERROR reg_dir_add_value(REG_KEY *p, const char *name, int type, void *data, int len, REG_VAL **value)
113 *value = reg_val_new(p, NULL);
114 (*value)->name = name?talloc_strdup((*value)->mem_ctx, name):NULL;
115 fullpath = reg_path_win2unix(strdup(reg_val_get_path(*value)));
117 fd = fopen(fullpath, "w+");
120 return WERR_NOT_SUPPORTED;
123 static WERROR reg_dir_del_value(REG_VAL *v)
126 return WERR_NOT_SUPPORTED;
129 static struct registry_ops reg_backend_dir = {
131 .open_registry = reg_dir_open,
132 .open_key = reg_dir_open_key,
133 .fetch_subkeys = reg_dir_fetch_subkeys,
134 .add_key = reg_dir_add_key,
135 .del_key = reg_dir_del_key,
136 .add_value = reg_dir_add_value,
137 .del_value = reg_dir_del_value,
140 NTSTATUS reg_dir_init(void)
142 return register_backend("registry", ®_backend_dir);