summaryrefslogtreecommitdiffstats
path: root/source4/lib/registry/dir.c
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2008-03-03 10:50:53 +0100
committerJelmer Vernooij <jelmer@samba.org>2008-03-03 10:50:53 +0100
commit7dd0cd26d32980d4edb9db5c77c98a2b112e24cb (patch)
tree025dad49b789c0e9f2eb03d87ec386295630b3f0 /source4/lib/registry/dir.c
parent80e9b72e018fb7d7f2cd5ff383e4a533b4ccc705 (diff)
parent4d4a898742a0439d3f60c84194b02901412f4679 (diff)
downloadsamba-7dd0cd26d32980d4edb9db5c77c98a2b112e24cb.tar.gz
samba-7dd0cd26d32980d4edb9db5c77c98a2b112e24cb.tar.xz
samba-7dd0cd26d32980d4edb9db5c77c98a2b112e24cb.zip
Merge branch 'v4-0-test' of ssh://git.samba.org/data/git/samba into v4-0-gmake3
Conflicts: source/Makefile source/build/smb_build/makefile.pm source/librpc/config.mk (This used to be commit 3e02fcfd3fb6683f51417ba39f4ec177494eff3e)
Diffstat (limited to 'source4/lib/registry/dir.c')
-rw-r--r--source4/lib/registry/dir.c60
1 files changed, 54 insertions, 6 deletions
diff --git a/source4/lib/registry/dir.c b/source4/lib/registry/dir.c
index 27cae8c490..dc3717e886 100644
--- a/source4/lib/registry/dir.c
+++ b/source4/lib/registry/dir.c
@@ -55,18 +55,66 @@ static WERROR reg_dir_add_key(TALLOC_CTX *mem_ctx,
return WERR_GENERAL_FAILURE;
}
+static WERROR reg_dir_delete_recursive(const char *name)
+{
+ DIR *d;
+ struct dirent *e;
+ WERROR werr;
+
+ d = opendir(name);
+ if (d == NULL) {
+ DEBUG(3,("Unable to open '%s': %s\n", name,
+ strerror(errno)));
+ return WERR_BADFILE;
+ }
+
+ while((e = readdir(d))) {
+ char *path;
+ struct stat stbuf;
+
+ if (ISDOT(e->d_name) || ISDOTDOT(e->d_name))
+ continue;
+
+ path = talloc_asprintf(name, "%s/%s", name, e->d_name);
+ if (!path)
+ return WERR_NOMEM;
+
+ stat(path, &stbuf);
+
+ if (!S_ISDIR(stbuf.st_mode)) {
+ if (unlink(path) < 0) {
+ talloc_free(path);
+ closedir(d);
+ return WERR_GENERAL_FAILURE;
+ }
+ } else {
+ werr = reg_dir_delete_recursive(path);
+ if (!W_ERROR_IS_OK(werr)) {
+ talloc_free(path);
+ closedir(d);
+ return werr;
+ }
+ }
+
+ talloc_free(path);
+ }
+ closedir(d);
+
+ if (rmdir(name) == 0)
+ return WERR_OK;
+ else if (errno == ENOENT)
+ return WERR_BADFILE;
+ else
+ return WERR_GENERAL_FAILURE;
+}
+
static WERROR reg_dir_del_key(const struct hive_key *k, const char *name)
{
struct dir_key *dk = talloc_get_type(k, struct dir_key);
char *child = talloc_asprintf(NULL, "%s/%s", dk->path, name);
WERROR ret;
- if (rmdir(child) == 0)
- ret = WERR_OK;
- else if (errno == ENOENT)
- ret = WERR_BADFILE;
- else
- ret = WERR_GENERAL_FAILURE;
+ ret = reg_dir_delete_recursive(child);
talloc_free(child);