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.
23 #include "system/dir.h"
25 static WERROR reg_dir_add_key(TALLOC_CTX *mem_ctx, struct registry_key *parent, const char *name, uint32_t access_mask, SEC_DESC *desc, struct registry_key **result)
29 asprintf(&path, "%s%s\\%s", parent->hive->location, parent->path, name);
30 path = reg_path_win2unix(path);
31 ret = mkdir(path, 0700);
33 if(ret == 0)return WERR_OK; /* FIXME */
34 return WERR_INVALID_PARAM;
37 static WERROR reg_dir_del_key(struct registry_key *k)
39 return (rmdir((char *)k->backend_data) == 0)?WERR_OK:WERR_GENERAL_FAILURE;
42 static WERROR reg_dir_open_key(TALLOC_CTX *mem_ctx, struct registry_hive *h, const char *name, struct registry_key **subkey)
46 struct registry_key *ret;
49 DEBUG(0, ("NULL pointer passed as directory name!"));
50 return WERR_INVALID_PARAM;
54 fullpath = talloc_asprintf(mem_ctx, "%s%s", h->location, name);
55 fullpath = reg_path_win2unix(fullpath);
57 d = opendir(fullpath);
59 DEBUG(3,("Unable to open '%s': %s\n", fullpath, strerror(errno)));
63 ret = talloc_p(mem_ctx, struct registry_key);
70 static WERROR reg_dir_key_by_index(TALLOC_CTX *mem_ctx, struct registry_key *k, int idx, struct registry_key **key)
73 char *fullpath = k->backend_data;
77 d = opendir(fullpath);
79 if(!d) return WERR_INVALID_PARAM;
81 while((e = readdir(d))) {
82 if( strcmp(e->d_name, ".") &&
83 strcmp(e->d_name, "..")) {
87 /* Check if file is a directory */
88 asprintf(&thispath, "%s/%s", fullpath, e->d_name);
89 stat(thispath, &stbuf);
91 if(S_ISDIR(stbuf.st_mode)) {
94 (*key) = talloc_p(mem_ctx, struct registry_key);
95 (*key)->name = e->d_name;
97 (*key)->backend_data = talloc_strdup(mem_ctx, thispath);
110 return WERR_NO_MORE_ITEMS;
113 static WERROR reg_dir_open(struct registry_hive *h, struct registry_key **key)
115 if(!h->location) return WERR_INVALID_PARAM;
117 *key = talloc_p(h, struct registry_key);
118 (*key)->backend_data = talloc_strdup(*key, h->location);
122 static WERROR reg_dir_set_value(struct registry_key *p, const char *name, int type, void *data, int len)
125 return WERR_NOT_SUPPORTED;
128 static WERROR reg_dir_del_value(struct registry_value *v)
131 return WERR_NOT_SUPPORTED;
134 static struct hive_operations reg_backend_dir = {
136 .open_hive = reg_dir_open,
137 .open_key = reg_dir_open_key,
138 .add_key = reg_dir_add_key,
139 .del_key = reg_dir_del_key,
140 .get_subkey_by_index = reg_dir_key_by_index,
141 .set_value = reg_dir_set_value,
142 .del_value = reg_dir_del_value,
145 NTSTATUS registry_dir_init(void)
147 return registry_register(®_backend_dir);