summaryrefslogtreecommitdiff
path: root/source3/libsmb
diff options
context:
space:
mode:
authorRichard Sharpe <sharpe@samba.org>2001-03-27 12:13:59 +0000
committerRichard Sharpe <sharpe@samba.org>2001-03-27 12:13:59 +0000
commit5e0734417c7cff16ee69ca8f97b84c2b62af9491 (patch)
tree5bf895776db354073f53fc0ed51a08fb4a8e884d /source3/libsmb
parentc3eb491c9233c37c5d96cb6712ed8ccea1bd606c (diff)
downloadsamba-5e0734417c7cff16ee69ca8f97b84c2b62af9491.tar.gz
samba-5e0734417c7cff16ee69ca8f97b84c2b62af9491.tar.bz2
samba-5e0734417c7cff16ee69ca8f97b84c2b62af9491.zip
One small Insure fix for a memory leak. More fixes to come perhaps ...
Also fixed an error return for smbc_rmdir so that we can distinguish between EACCES and ENOTEMPTY (This used to be commit f204901fcc11eb3299cc6c7f3793fc3c7bd6bc57)
Diffstat (limited to 'source3/libsmb')
-rw-r--r--source3/libsmb/libsmbclient.c54
1 files changed, 52 insertions, 2 deletions
diff --git a/source3/libsmb/libsmbclient.c b/source3/libsmb/libsmbclient.c
index 43ccd6486a..826b5fdeb5 100644
--- a/source3/libsmb/libsmbclient.c
+++ b/source3/libsmb/libsmbclient.c
@@ -553,7 +553,9 @@ int smbc_open(const char *fname, int flags, mode_t mode)
}
- if (path[strlen(path) - 1] == '\\') {
+ /* Hmmm, the test for a directory is suspect here ... FIXME */
+
+ if (strlen(path) > 0 && path[strlen(path) - 1] == '\\') {
fd = -1;
@@ -801,6 +803,7 @@ int smbc_close(int fd)
}
+ if (fe->fname) free(fe->fname);
free(fe);
smbc_file_table[fd - smbc_start_fd] = NULL;
@@ -1741,7 +1744,12 @@ int smbc_closedir(int fd)
smbc_remove_dir(fe); /* Clean it up */
- if (fe) free(fe); /* Free the space too */
+ if (fe) {
+
+ if (fe->fname) free(fe->fname);
+ free(fe); /* Free the space too */
+
+ }
smbc_file_table[fd - smbc_start_fd] = NULL;
@@ -1989,6 +1997,20 @@ int smbc_mkdir(const char *fname, mode_t mode)
}
/*
+ * Our list function simply checks to see if a directory is not empty
+ */
+
+static int smbc_rmdir_dirempty = True;
+
+static void rmdir_list_fn(file_info *finfo, const char *mask, void *state)
+{
+
+ if (strncmp(finfo->name, ".", 1) != 0 && strncmp(finfo->name, "..", 2) != 0)
+ smbc_rmdir_dirempty = False;
+
+}
+
+/*
* Routine to remove a directory
*/
@@ -2050,6 +2072,34 @@ int smbc_rmdir(const char *fname)
if (!cli_rmdir(&srv->cli, path)) {
errno = smbc_errno(&srv->cli);
+
+ if (errno == EACCES) { /* Check if the dir empty or not */
+
+ pstring lpath; /* Local storage to avoid buffer overflows */
+
+ smbc_rmdir_dirempty = True; /* Make this so ... */
+
+ pstrcpy(lpath, path);
+ pstrcat(lpath, "\\*");
+
+ if (cli_list(&srv->cli, lpath, aDIR | aSYSTEM | aHIDDEN, rmdir_list_fn,
+ NULL) < 0) {
+
+ /* Fix errno to ignore latest error ... */
+
+ DEBUG(5, ("smbc_rmdir: cli_list returned an error: %d\n",
+ smbc_errno(&srv->cli)));
+ errno = EACCES;
+
+ }
+
+ if (smbc_rmdir_dirempty)
+ errno = EACCES;
+ else
+ errno = ENOTEMPTY;
+
+ }
+
return -1;
}