Lines 527-533
int
Link Here
|
527 |
validate_access(char **filep, int mode) |
527 |
validate_access(char **filep, int mode) |
528 |
{ |
528 |
{ |
529 |
struct stat stbuf; |
529 |
struct stat stbuf; |
530 |
int fd; |
530 |
int fd, crq; |
531 |
struct dirlist *dirp; |
531 |
struct dirlist *dirp; |
532 |
static char pathname[MAXPATHLEN]; |
532 |
static char pathname[MAXPATHLEN]; |
533 |
char *filename = *filep; |
533 |
char *filename = *filep; |
Lines 554-569
validate_access(char **filep, int mode)
Link Here
|
554 |
/* If directory list is empty, allow access to any file */ |
554 |
/* If directory list is empty, allow access to any file */ |
555 |
if (dirp->name == NULL && dirp != dirs) |
555 |
if (dirp->name == NULL && dirp != dirs) |
556 |
return (EACCESS); |
556 |
return (EACCESS); |
557 |
if (stat(filename, &stbuf) < 0) |
557 |
|
558 |
return (errno == ENOENT ? ENOTFOUND : EACCESS); |
558 |
crq = 0; |
559 |
if ((stbuf.st_mode & S_IFMT) != S_IFREG) |
559 |
if (stat(filename, &stbuf) < 0) { |
560 |
return (ENOTFOUND); |
560 |
if (create_new && (mode == WRQ) && (errno == ENOENT)) |
|
|
561 |
crq = 1; |
562 |
if (!crq) |
563 |
return (errno == ENOENT ? ENOTFOUND : EACCESS); |
564 |
} |
565 |
if (!crq) { |
566 |
if ((stbuf.st_mode & S_IFMT) != S_IFREG) |
567 |
return (ENOTFOUND); |
568 |
} |
561 |
if (mode == RRQ) { |
569 |
if (mode == RRQ) { |
562 |
if ((stbuf.st_mode & S_IROTH) == 0) |
570 |
if ((stbuf.st_mode & S_IROTH) == 0) |
563 |
return (EACCESS); |
571 |
return (EACCESS); |
564 |
} else { |
572 |
} else { |
565 |
if ((stbuf.st_mode & S_IWOTH) == 0) |
573 |
if (!crq) { |
566 |
return (EACCESS); |
574 |
if ((stbuf.st_mode & S_IWOTH) == 0) |
|
|
575 |
return (EACCESS); |
576 |
} |
567 |
} |
577 |
} |
568 |
} else { |
578 |
} else { |
569 |
int err; |
579 |
int err; |