r19011: Attempt to fix the BSD RAW-CHKPATH failures: In Samba3 we rely on opendir
authorVolker Lendecke <vlendec@samba.org>
Sat, 30 Sep 2006 14:12:02 +0000 (14:12 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:14:57 +0000 (12:14 -0500)
returning ENOTDIR when the file opened is not a directory. Can we merge this
back into Samba4?

Volker

source/lib/replace/repdir_getdents.c
source/lib/replace/repdir_getdirentries.c

index 07b9568dc1a71f4b89786a444ebbc26395201cc8..3bf76ee858f0c6bc42005481db42b8ffd8f4fc3c 100644 (file)
@@ -68,6 +68,7 @@ struct dir_buf {
 DIR *opendir(const char *dname)
 {
        struct dir_buf *d;
+       struct stat sb;
        d = malloc(sizeof(*d));
        if (d == NULL) {
                errno = ENOMEM;
@@ -78,6 +79,17 @@ DIR *opendir(const char *dname)
                free(d);
                return NULL;
        }
+       if (fstat(d->fd, &sb) < 0) {
+                close(d->fd);
+                free(d);
+                return NULL;
+        }
+        if (!S_ISDIR(sb.st_mode)) {
+                close(d->fd);
+                free(d);   
+                errno = ENOTDIR;
+                return NULL;
+        }
        d->ofs = 0;
        d->seekpos = 0;
        d->nbytes = 0;
index 9e4b63145cd9edf55d935396771c8156f4ae5a65..ee1d2184566415e1988d488c18f0366b2d65ea3d 100644 (file)
@@ -70,6 +70,7 @@ struct dir_buf {
 DIR *opendir(const char *dname)
 {
        struct dir_buf *d;
+       struct stat sb;
        d = malloc(sizeof(*d));
        if (d == NULL) {
                errno = ENOMEM;
@@ -80,6 +81,17 @@ DIR *opendir(const char *dname)
                free(d);
                return NULL;
        }
+       if (fstat(d->fd, &sb) < 0) {
+                close(d->fd);
+                free(d);
+                return NULL;
+        }
+        if (!S_ISDIR(sb.st_mode)) {
+                close(d->fd);
+                free(d);   
+                errno = ENOTDIR;
+                return NULL;
+        }
        d->ofs = 0;
        d->seekpos = 0;
        d->nbytes = 0;