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 DIR *reg_dir_dir(REG_HANDLE *h, const char *base, const char *name)
28 asprintf(&path, "%s/%s/%s", h->location, base, name);
29 path = reg_path_win2unix(path);
33 printf("Unable to open '%s'\n", path);
40 static BOOL reg_dir_add_key(REG_KEY *parent, const char *name)
44 asprintf(&path, "%s/%s/%s", parent->handle->location, reg_key_get_path(parent), name);
45 path = reg_path_win2unix(path);
46 ret = mkdir(path, 0700);
51 static BOOL reg_dir_del_key(REG_KEY *k)
55 asprintf(&path, "%s/%s", k->handle->location, reg_key_get_path(k));
56 path = reg_path_win2unix(path);
62 static REG_KEY *reg_dir_open_key(REG_HANDLE *h, const char *name)
67 DEBUG(0, ("NULL pointer passed as directory name!"));
70 fullpath = reg_path_win2unix(strdup(name));
71 d = reg_dir_dir(h, "", fullpath);
74 if(d) return reg_key_new_abs(name, h, d);
78 static BOOL reg_dir_fetch_subkeys(REG_KEY *k, int *count, REG_KEY ***r)
80 DIR *d = (DIR *)k->backend_data;
87 ar = malloc(sizeof(REG_KEY *) * max);
89 while((e = readdir(d))) {
90 if(e->d_type == DT_DIR &&
91 strcmp(e->d_name, ".") &&
92 strcmp(e->d_name, "..")) {
93 char *fullpath = reg_path_win2unix(strdup(k->path));
94 ar[(*count)] = reg_key_new_rel(e->d_name, k, reg_dir_dir(k->handle, fullpath, e->d_name));
96 if(ar[(*count)])(*count)++;
100 ar = realloc(ar, sizeof(REG_KEY *) * max);
109 static BOOL reg_dir_open(REG_HANDLE *h, const char *loc, BOOL try) {
110 if(!loc) return False;
114 static void dir_free(REG_KEY *k)
116 closedir((DIR *)k->backend_data);
119 static REG_VAL *reg_dir_add_value(REG_KEY *p, const char *name, int type, void *data, int len)
121 REG_VAL *ret = reg_val_new(p, NULL);
124 ret->name = name?strdup(name):NULL;
125 fullpath = reg_path_win2unix(strdup(reg_val_get_path(ret)));
127 fd = fopen(fullpath, "w+");
133 static BOOL reg_dir_del_value(REG_VAL *v)
135 char *fullpath = reg_path_win2unix(strdup(reg_val_get_path(v)));
139 static REG_OPS reg_backend_dir = {
141 .open_registry = reg_dir_open,
142 .open_key = reg_dir_open_key,
143 .fetch_subkeys = reg_dir_fetch_subkeys,
144 .add_key = reg_dir_add_key,
145 .del_key = reg_dir_del_key,
146 .add_value = reg_dir_add_value,
147 .del_value = reg_dir_del_value,
148 .free_key_backend_data = dir_free
151 NTSTATUS reg_dir_init(void)
153 return register_backend("registry", ®_backend_dir);