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 3 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, see <http://www.gnu.org/licenses/>.
22 #include "system/dir.h"
23 #include "system/filesys.h"
25 static WERROR reg_dir_add_key(TALLOC_CTX *mem_ctx, const struct registry_key *parent, const char *name, uint32_t access_mask, struct security_descriptor *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(const struct registry_key *k, const char *name)
39 char *child = talloc_asprintf(NULL, "%s/%s", (char *)k->backend_data, name);
42 if (rmdir(child) == 0) ret = WERR_OK; else ret = WERR_GENERAL_FAILURE;
49 static WERROR reg_dir_open_key(TALLOC_CTX *mem_ctx, const struct registry_key *p, const char *name, struct registry_key **subkey)
52 char *fullpath, *unixpath;
53 struct registry_key *ret;
56 DEBUG(0, ("NULL pointer passed as directory name!"));
57 return WERR_INVALID_PARAM;
61 fullpath = talloc_asprintf(mem_ctx, "%s/%s", (char *)p->backend_data, name);
62 unixpath = reg_path_win2unix(fullpath);
64 d = opendir(unixpath);
66 DEBUG(3,("Unable to open '%s': %s\n", unixpath, strerror(errno)));
70 ret = talloc(mem_ctx, struct registry_key);
73 ret->backend_data = unixpath;
78 static WERROR reg_dir_key_by_index(TALLOC_CTX *mem_ctx, const struct registry_key *k, int idx, struct registry_key **key)
81 char *fullpath = k->backend_data;
85 d = opendir(fullpath);
87 if(!d) return WERR_INVALID_PARAM;
89 while((e = readdir(d))) {
90 if(!ISDOT(e->d_name) && !ISDOTDOT(e->d_name)) {
94 /* Check if file is a directory */
95 asprintf(&thispath, "%s/%s", fullpath, e->d_name);
96 stat(thispath, &stbuf);
98 if(S_ISDIR(stbuf.st_mode)) {
100 (*key) = talloc(mem_ctx, struct registry_key);
101 (*key)->name = talloc_strdup(*key, e->d_name);
103 (*key)->backend_data = talloc_strdup(*key, thispath);
117 return WERR_NO_MORE_ITEMS;
120 static WERROR reg_dir_open(struct registry_hive *h, struct registry_key **key)
122 if(!h->location) return WERR_INVALID_PARAM;
124 *key = talloc(h, struct registry_key);
125 (*key)->backend_data = talloc_strdup(*key, h->location);
129 static struct hive_operations reg_backend_dir = {
131 .open_hive = reg_dir_open,
132 .open_key = reg_dir_open_key,
133 .add_key = reg_dir_add_key,
134 .del_key = reg_dir_del_key,
135 .get_subkey_by_index = reg_dir_key_by_index
138 NTSTATUS registry_dir_init(void)
140 return registry_register(®_backend_dir);