summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Sharpe <sharpe@samba.org>2005-04-03 21:37:13 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:11:24 -0500
commitcf97980f3129b9a3eb7bdf3ae95f4fd99a597259 (patch)
treefcc86f2b684a574e943b3c0a35362d75fca332a2
parent6db5d09dba3f1f6111b5fcd89cb303c95adec6bd (diff)
downloadsamba-cf97980f3129b9a3eb7bdf3ae95f4fd99a597259.tar.gz
samba-cf97980f3129b9a3eb7bdf3ae95f4fd99a597259.tar.bz2
samba-cf97980f3129b9a3eb7bdf3ae95f4fd99a597259.zip
r6187: 1. Make sure that we don't try to delete . and .. in a more portable way.
2. Also, don't try to delete directories. I am not entirely happy with this patch, and the fact that there is a define for HAVE_SYS_STAT_H suggests that there are some systems for which stat will not be defined, which means that the patch is not entirely portable. (This used to be commit fe7ddad7d44a49b2efe81cb3d0a5b2d09d1892ab)
-rw-r--r--source4/smbd/server.c44
1 files changed, 34 insertions, 10 deletions
diff --git a/source4/smbd/server.c b/source4/smbd/server.c
index c5dee5f7ad..1357541cea 100644
--- a/source4/smbd/server.c
+++ b/source4/smbd/server.c
@@ -55,17 +55,41 @@ static void cleanup_tmp_files(void)
}
for (de=readdir(dir);de;de=readdir(dir)) {
- char *fname = talloc_asprintf(mem_ctx, "%s/%s", path, de->d_name);
- int ret = unlink(fname);
- if (ret == -1 &&
- errno != ENOENT &&
- errno != EISDIR &&
- errno != EISDIR) {
- DEBUG(0,("Unabled to delete '%s' - %s\n",
- fname, strerror(errno)));
- smb_panic("unable to cleanup tmp files");
+ /*
+ * Don't try to delete . and ..
+ */
+ if (strcmp(de->d_name, ".") != 0 &&
+ strcmp(de->d_name, "..")) {
+ char *fname = talloc_asprintf(mem_ctx, "%s/%s", path, de->d_name);
+ int ret = unlink(fname);
+ if (ret == -1 &&
+ errno != ENOENT &&
+ errno != EPERM &&
+ errno != EISDIR) {
+ DEBUG(0,("Unabled to delete '%s' - %s\n",
+ fname, strerror(errno)));
+ smb_panic("unable to cleanup tmp files");
+ }
+ if (ret == -1 &&
+ errno == EPERM) {
+ /*
+ * If it is a dir, don't complain
+ * NOTE! The test will only happen if we have
+ * sys/stat.h, otherwise we will always error out
+ */
+#ifdef HAVE_SYS_STAT_H
+ struct stat sb;
+ if (stat(fname, &sb) != -1 &&
+ !S_ISDIR(sb.st_mode))
+#endif
+ {
+ DEBUG(0,("Unable to delete '%s' - %s\n",
+ fname, strerror(errno)));
+ smb_panic("unable to cleanup tmp files");
+ }
+ }
+ talloc_free(fname);
}
- talloc_free(fname);
}
closedir(dir);