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"
24 #include "system/filesys.h"
26 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)
30 asprintf(&path, "%s%s\\%s", parent->hive->location, parent->path, name);
31 path = reg_path_win2unix(path);
32 ret = mkdir(path, 0700);
34 if(ret == 0)return WERR_OK; /* FIXME */
35 return WERR_INVALID_PARAM;
38 static WERROR reg_dir_del_key(const struct registry_key *k, const char *name)
40 char *child = talloc_asprintf(NULL, "%s/%s", (char *)k->backend_data, name);
43 if (rmdir(child) == 0) ret = WERR_OK; else ret = WERR_GENERAL_FAILURE;
50 static WERROR reg_dir_open_key(TALLOC_CTX *mem_ctx, const struct registry_key *p, const char *name, struct registry_key **subkey)
53 char *fullpath, *unixpath;
54 struct registry_key *ret;
57 DEBUG(0, ("NULL pointer passed as directory name!"));
58 return WERR_INVALID_PARAM;
62 fullpath = talloc_asprintf(mem_ctx, "%s/%s", (char *)p->backend_data, name);
63 unixpath = reg_path_win2unix(fullpath);
65 d = opendir(unixpath);
67 DEBUG(3,("Unable to open '%s': %s\n", unixpath, strerror(errno)));
71 ret = talloc(mem_ctx, struct registry_key);
74 ret->backend_data = unixpath;
79 static WERROR reg_dir_key_by_index(TALLOC_CTX *mem_ctx, const struct registry_key *k, int idx, struct registry_key **key)
82 char *fullpath = k->backend_data;
86 d = opendir(fullpath);
88 if(!d) return WERR_INVALID_PARAM;
90 while((e = readdir(d))) {
91 if( strcmp(e->d_name, ".") &&
92 strcmp(e->d_name, "..")) {
96 /* Check if file is a directory */
97 asprintf(&thispath, "%s/%s", fullpath, e->d_name);
98 stat(thispath, &stbuf);
100 if(S_ISDIR(stbuf.st_mode)) {
102 (*key) = talloc(mem_ctx, struct registry_key);
103 (*key)->name = e->d_name;
105 (*key)->backend_data = talloc_strdup(mem_ctx, thispath);
119 return WERR_NO_MORE_ITEMS;
122 static WERROR reg_dir_open(struct registry_hive *h, struct registry_key **key)
124 if(!h->location) return WERR_INVALID_PARAM;
126 *key = talloc(h, struct registry_key);
127 (*key)->backend_data = talloc_strdup(*key, h->location);
131 static struct hive_operations reg_backend_dir = {
133 .open_hive = reg_dir_open,
134 .open_key = reg_dir_open_key,
135 .add_key = reg_dir_add_key,
136 .del_key = reg_dir_del_key,
137 .get_subkey_by_index = reg_dir_key_by_index
140 NTSTATUS registry_dir_init(void)
142 return registry_register(®_backend_dir);