Return-Path: Delivered-To: apmail-apache-cvs-archive@apache.org Received: (qmail 87104 invoked by uid 500); 3 Jul 2000 12:06:44 -0000 Mailing-List: contact apache-cvs-help@apache.org; run by ezmlm Precedence: bulk X-No-Archive: yes Reply-To: new-httpd@apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list apache-cvs@apache.org Received: (qmail 87079 invoked by uid 500); 3 Jul 2000 12:06:43 -0000 Delivered-To: apmail-apache-2.0-cvs@apache.org Date: 3 Jul 2000 12:06:42 -0000 Message-ID: <20000703120642.87074.qmail@locus.apache.org> From: gstein@locus.apache.org To: apache-2.0-cvs@apache.org Subject: cvs commit: apache-2.0/src/lib/apr/file_io/win32 filestat.c gstein 00/07/03 05:06:40 Modified: src/lib/apr/include apr_file_io.h src/lib/apr/file_io/os2 filestat.c src/lib/apr/file_io/unix dir.c fileacc.c fileio.h filestat.c open.c pipe.c src/lib/apr/file_io/win32 filestat.c Log: add ap_finfo_t.device add ap_setfileperms() for setting file permissions (chmod cover). - OS/2 and Win32 currently return APR_ENOTIMPL fix the file perm handling in APR: some conversion between ap_fileperms_t and mode_t was not occurring; adding new conversion function; renamed old conversion func. Revision Changes Path 1.58 +23 -3 apache-2.0/src/lib/apr/include/apr_file_io.h Index: apr_file_io.h =================================================================== RCS file: /home/cvs/apache-2.0/src/lib/apr/include/apr_file_io.h,v retrieving revision 1.57 retrieving revision 1.58 diff -u -r1.57 -r1.58 --- apr_file_io.h 2000/06/20 19:36:33 1.57 +++ apr_file_io.h 2000/07/03 12:06:26 1.58 @@ -111,6 +111,7 @@ typedef uid_t ap_uid_t; typedef gid_t ap_gid_t; typedef ino_t ap_ino_t; +typedef dev_t ap_dev_t; struct ap_finfo_t { ap_fileperms_t protection; @@ -118,6 +119,7 @@ ap_uid_t user; ap_gid_t group; ap_ino_t inode; + ap_dev_t device; ap_off_t size; ap_time_t atime; ap_time_t mtime; @@ -362,7 +364,7 @@ B arg 1) The string to write. - arg 2) The file descriptor to write to from + arg 2) The file descriptor to write to =cut */ @@ -402,14 +404,32 @@ =head1 ap_status_t ap_getfileinfo(ap_finfo_t *finfo, ap_file_t *thefile) -B +B arg 1) Where to store the information about the file. - arg 2) The file to get information about. + arg 2) The file to get information about. =cut */ ap_status_t ap_getfileinfo(ap_finfo_t *finfo, ap_file_t *thefile); + +/* + +=head1 ap_status_t ap_setfileperms(const char *fname, ap_fileperms_t perms) + +B + + arg 1) The file (name) to apply the permissions to. + arg 2) The permission bits to apply to the file. + + Some platforms may not be able to apply all of the available permission + bits; APR_INCOMPLETE will be returned if some permissions are specified + which could not be set. + + Platforms which do not implement this feature will return APR_ENOTIMPL. +=cut + */ +ap_status_t ap_setfileperms(const char *fname, ap_fileperms_t perms); /* 1.10 +5 -0 apache-2.0/src/lib/apr/file_io/os2/filestat.c Index: filestat.c =================================================================== RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/os2/filestat.c,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- filestat.c 2000/04/14 15:58:21 1.9 +++ filestat.c 2000/07/03 12:06:27 1.10 @@ -73,6 +73,7 @@ finfo->user = 0; finfo->group = 0; finfo->inode = 0; + finfo->device = 0; finfo->size = fstatus->cbFile; ap_os2_time_to_ap_time(&finfo->atime, fstatus->fdateLastAccess, fstatus->ftimeLastAccess ); ap_os2_time_to_ap_time(&finfo->mtime, fstatus->fdateLastWrite, fstatus->ftimeLastWrite ); @@ -136,6 +137,10 @@ return APR_OS2_STATUS(rc); } +ap_status_t ap_setfileperms(const char *fname, ap_fileperms_t perms) +{ + return APR_ENOTIMPL; +} ap_status_t ap_stat(ap_finfo_t *finfo, const char *fname, ap_pool_t *cont) 1.34 +1 -1 apache-2.0/src/lib/apr/file_io/unix/dir.c Index: dir.c =================================================================== RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/unix/dir.c,v retrieving revision 1.33 retrieving revision 1.34 diff -u -r1.33 -r1.34 --- dir.c 2000/04/30 21:17:55 1.33 +++ dir.c 2000/07/03 12:06:28 1.34 @@ -142,7 +142,7 @@ ap_status_t ap_make_dir(const char *path, ap_fileperms_t perm, ap_pool_t *cont) { - mode_t mode = ap_unix_get_fileperms(perm); + mode_t mode = ap_unix_perms2mode(perm); if (mkdir(path, mode) == 0) { return APR_SUCCESS; 1.29 +51 -23 apache-2.0/src/lib/apr/file_io/unix/fileacc.c Index: fileacc.c =================================================================== RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/unix/fileacc.c,v retrieving revision 1.28 retrieving revision 1.29 diff -u -r1.28 -r1.29 --- fileacc.c 2000/05/24 22:32:28 1.28 +++ fileacc.c 2000/07/03 12:06:28 1.29 @@ -82,32 +82,60 @@ } #if !defined(OS2) && !defined(WIN32) -mode_t ap_unix_get_fileperms(ap_fileperms_t mode) +mode_t ap_unix_perms2mode(ap_fileperms_t perms) { - mode_t rv = 0; + mode_t mode = 0; - if (mode & APR_UREAD) - rv |= S_IRUSR; - if (mode & APR_UWRITE) - rv |= S_IWUSR; - if (mode & APR_UEXECUTE) - rv |= S_IXUSR; - - if (mode & APR_GREAD) - rv |= S_IRGRP; - if (mode & APR_GWRITE) - rv |= S_IWGRP; - if (mode & APR_GEXECUTE) - rv |= S_IXGRP; - - if (mode & APR_WREAD) - rv |= S_IROTH; - if (mode & APR_WWRITE) - rv |= S_IWOTH; - if (mode & APR_WEXECUTE) - rv |= S_IXOTH; + if (perms & APR_UREAD) + mode |= S_IRUSR; + if (perms & APR_UWRITE) + mode |= S_IWUSR; + if (perms & APR_UEXECUTE) + mode |= S_IXUSR; - return rv; + if (perms & APR_GREAD) + mode |= S_IRGRP; + if (perms & APR_GWRITE) + mode |= S_IWGRP; + if (perms & APR_GEXECUTE) + mode |= S_IXGRP; + + if (perms & APR_WREAD) + mode |= S_IROTH; + if (perms & APR_WWRITE) + mode |= S_IWOTH; + if (perms & APR_WEXECUTE) + mode |= S_IXOTH; + + return mode; +} + +ap_fileperms_t ap_unix_mode2perms(mode_t mode) +{ + ap_fileperms_t perms = 0; + + if (mode & S_IRUSR) + perms |= APR_UREAD; + if (mode & S_IWUSR) + perms |= APR_UWRITE; + if (mode & S_IXUSR) + perms |= APR_UEXECUTE; + + if (mode & S_IRGRP) + perms |= APR_GREAD; + if (mode & S_IWGRP) + perms |= APR_GWRITE; + if (mode & S_IXGRP) + perms |= APR_GEXECUTE; + + if (mode & S_IROTH) + perms |= APR_WREAD; + if (mode & S_IWOTH) + perms |= APR_WWRITE; + if (mode & S_IXOTH) + perms |= APR_WEXECUTE; + + return perms; } #endif 1.25 +3 -1 apache-2.0/src/lib/apr/file_io/unix/fileio.h Index: fileio.h =================================================================== RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/unix/fileio.h,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- fileio.h 2000/06/28 14:33:29 1.24 +++ fileio.h 2000/07/03 12:06:29 1.25 @@ -143,7 +143,9 @@ }; ap_status_t ap_unix_file_cleanup(void *); -mode_t ap_unix_get_fileperms(ap_fileperms_t); + +mode_t ap_unix_perms2mode(ap_fileperms_t perms); +ap_fileperms_t ap_unix_mode2perms(mode_t mode); #endif /* ! FILE_IO_H */ 1.27 +13 -3 apache-2.0/src/lib/apr/file_io/unix/filestat.c Index: filestat.c =================================================================== RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/unix/filestat.c,v retrieving revision 1.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- filestat.c 2000/06/12 15:28:50 1.26 +++ filestat.c 2000/07/03 12:06:29 1.27 @@ -85,12 +85,13 @@ struct stat info; if (fstat(thefile->filedes, &info) == 0) { - finfo->protection = info.st_mode; + finfo->protection = ap_unix_mode2perms(info.st_mode); finfo->filetype = filetype_from_mode(info.st_mode); finfo->user = info.st_uid; finfo->group = info.st_gid; finfo->size = info.st_size; finfo->inode = info.st_ino; + finfo->device = info.st_dev; ap_ansi_time_to_ap_time(&finfo->atime, info.st_atime); ap_ansi_time_to_ap_time(&finfo->mtime, info.st_mtime); ap_ansi_time_to_ap_time(&finfo->ctime, info.st_ctime); @@ -101,12 +102,21 @@ } } +ap_status_t ap_setfileperms(const char *fname, ap_fileperms_t perms) +{ + mode_t mode = ap_unix_perms2mode(perms); + + if (chmod(fname, mode) == -1) + return errno; + return APR_SUCCESS; +} + ap_status_t ap_stat(ap_finfo_t *finfo, const char *fname, ap_pool_t *cont) { struct stat info; if (stat(fname, &info) == 0) { - finfo->protection = info.st_mode; + finfo->protection = ap_unix_mode2perms(info.st_mode); finfo->filetype = filetype_from_mode(info.st_mode); finfo->user = info.st_uid; finfo->group = info.st_gid; @@ -127,7 +137,7 @@ struct stat info; if (lstat(fname, &info) == 0) { - finfo->protection = info.st_mode; + finfo->protection = ap_unix_mode2perms(info.st_mode); finfo->filetype = filetype_from_mode(info.st_mode); finfo->user = info.st_uid; finfo->group = info.st_gid; 1.60 +1 -1 apache-2.0/src/lib/apr/file_io/unix/open.c Index: open.c =================================================================== RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/unix/open.c,v retrieving revision 1.59 retrieving revision 1.60 diff -u -r1.59 -r1.60 --- open.c 2000/06/27 01:26:15 1.59 +++ open.c 2000/07/03 12:06:29 1.60 @@ -145,7 +145,7 @@ (*new)->filedes = open(fname, oflags, 0666); } else { - (*new)->filedes = open(fname, oflags, ap_unix_get_fileperms(perm)); + (*new)->filedes = open(fname, oflags, ap_unix_perms2mode(perm)); } if ((*new)->filedes < 0) { 1.36 +1 -1 apache-2.0/src/lib/apr/file_io/unix/pipe.c Index: pipe.c =================================================================== RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/unix/pipe.c,v retrieving revision 1.35 retrieving revision 1.36 diff -u -r1.35 -r1.36 --- pipe.c 2000/06/20 19:36:25 1.35 +++ pipe.c 2000/07/03 12:06:30 1.36 @@ -183,7 +183,7 @@ ap_status_t ap_create_namedpipe(const char *filename, ap_fileperms_t perm, ap_pool_t *cont) { - mode_t mode = ap_unix_get_fileperms(perm); + mode_t mode = ap_unix_perms2mode(perm); if (mkfifo(filename, mode) == -1) { return errno; 1.22 +6 -0 apache-2.0/src/lib/apr/file_io/win32/filestat.c Index: filestat.c =================================================================== RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/win32/filestat.c,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- filestat.c 2000/06/20 03:13:30 1.21 +++ filestat.c 2000/07/03 12:06:38 1.22 @@ -130,6 +130,7 @@ finfo->user = 0; finfo->group = 0; finfo->inode = 0; + finfo->device = 0; /* ### use drive letter - 'A' ? */ /* Filetype - Directory or file: this case _will_ never happen */ if (FileInformation.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { @@ -179,6 +180,11 @@ finfo->size = FileInformation.nFileSizeLow; return APR_SUCCESS; +} + +ap_status_t ap_setfileperms(const char *fname, ap_fileperms_t perms) +{ + return APR_ENOTIMPL; } ap_status_t ap_stat(ap_finfo_t *finfo, const char *fname, ap_pool_t *cont)