diff options
author | gstein <gstein@13f79535-47bb-0310-9956-ffa450edef68> | 2000-07-03 12:06:38 +0000 |
---|---|---|
committer | gstein <gstein@13f79535-47bb-0310-9956-ffa450edef68> | 2000-07-03 12:06:38 +0000 |
commit | 14384e0c1e1280647c7d26408d05fab41bfa6f46 (patch) | |
tree | 47e85b7b21eb1ba24457d620a9a27a925545e78c | |
parent | 5dd1707e7a337bcc93aa69a297b413f5aa0f973e (diff) | |
download | libapr-14384e0c1e1280647c7d26408d05fab41bfa6f46.tar.gz |
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.
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@60292 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | file_io/os2/filestat.c | 5 | ||||
-rw-r--r-- | file_io/unix/dir.c | 2 | ||||
-rw-r--r-- | file_io/unix/fileacc.c | 70 | ||||
-rw-r--r-- | file_io/unix/fileio.h | 4 | ||||
-rw-r--r-- | file_io/unix/filestat.c | 16 | ||||
-rw-r--r-- | file_io/unix/open.c | 2 | ||||
-rw-r--r-- | file_io/unix/pipe.c | 2 | ||||
-rw-r--r-- | file_io/win32/filestat.c | 6 | ||||
-rw-r--r-- | include/apr_file_io.h | 26 | ||||
-rw-r--r-- | include/arch/unix/fileio.h | 4 |
10 files changed, 105 insertions, 32 deletions
diff --git a/file_io/os2/filestat.c b/file_io/os2/filestat.c index 429686c28..96d0deb2d 100644 --- a/file_io/os2/filestat.c +++ b/file_io/os2/filestat.c @@ -73,6 +73,7 @@ static void FS3_to_finfo(ap_finfo_t *finfo, FILESTATUS3 *fstatus) 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 @@ ap_status_t ap_getfileinfo(ap_finfo_t *finfo, ap_file_t *thefile) 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) diff --git a/file_io/unix/dir.c b/file_io/unix/dir.c index 9d39d893d..8791620e9 100644 --- a/file_io/unix/dir.c +++ b/file_io/unix/dir.c @@ -142,7 +142,7 @@ ap_status_t ap_rewinddir(ap_dir_t *thedir) 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; diff --git a/file_io/unix/fileacc.c b/file_io/unix/fileacc.c index 32a574dc3..4723aada9 100644 --- a/file_io/unix/fileacc.c +++ b/file_io/unix/fileacc.c @@ -82,32 +82,60 @@ ap_status_t ap_get_filename(char **new, ap_file_t *thefile) } #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 (perms & APR_UREAD) + mode |= S_IRUSR; + if (perms & APR_UWRITE) + mode |= S_IWUSR; + if (perms & APR_UEXECUTE) + mode |= S_IXUSR; - if (mode & APR_GREAD) - rv |= S_IRGRP; - if (mode & APR_GWRITE) - rv |= S_IWGRP; - if (mode & APR_GEXECUTE) - rv |= S_IXGRP; + if (perms & APR_GREAD) + mode |= S_IRGRP; + if (perms & APR_GWRITE) + mode |= S_IWGRP; + if (perms & APR_GEXECUTE) + mode |= 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_WREAD) + mode |= S_IROTH; + if (perms & APR_WWRITE) + mode |= S_IWOTH; + if (perms & APR_WEXECUTE) + mode |= S_IXOTH; - return rv; + 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 diff --git a/file_io/unix/fileio.h b/file_io/unix/fileio.h index 06e38ee84..c91bb453d 100644 --- a/file_io/unix/fileio.h +++ b/file_io/unix/fileio.h @@ -143,7 +143,9 @@ struct ap_dir_t { }; 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 */ diff --git a/file_io/unix/filestat.c b/file_io/unix/filestat.c index 7ed8a238f..8f593b8df 100644 --- a/file_io/unix/filestat.c +++ b/file_io/unix/filestat.c @@ -85,12 +85,13 @@ ap_status_t ap_getfileinfo(ap_finfo_t *finfo, ap_file_t *thefile) 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_getfileinfo(ap_finfo_t *finfo, ap_file_t *thefile) } } +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 @@ ap_status_t ap_lstat(ap_finfo_t *finfo, const char *fname, ap_pool_t *cont) 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; diff --git a/file_io/unix/open.c b/file_io/unix/open.c index ce5731e5e..a46136370 100644 --- a/file_io/unix/open.c +++ b/file_io/unix/open.c @@ -145,7 +145,7 @@ ap_status_t ap_open(ap_file_t **new, const char *fname, ap_int32_t flag, ap_fil (*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) { diff --git a/file_io/unix/pipe.c b/file_io/unix/pipe.c index f68fcbcf7..97bbf72ee 100644 --- a/file_io/unix/pipe.c +++ b/file_io/unix/pipe.c @@ -183,7 +183,7 @@ ap_status_t ap_create_pipe(ap_file_t **in, ap_file_t **out, ap_pool_t *cont) 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; diff --git a/file_io/win32/filestat.c b/file_io/win32/filestat.c index f81b09f8c..f66fbf936 100644 --- a/file_io/win32/filestat.c +++ b/file_io/win32/filestat.c @@ -130,6 +130,7 @@ ap_status_t ap_getfileinfo(ap_finfo_t *finfo, ap_file_t *thefile) 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) { @@ -181,6 +182,11 @@ ap_status_t ap_getfileinfo(ap_finfo_t *finfo, ap_file_t *thefile) 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) { /* WIN32_FILE_ATTRIBUTE_DATA is an exact subset of the first diff --git a/include/apr_file_io.h b/include/apr_file_io.h index de5e6708f..5d24972b9 100644 --- a/include/apr_file_io.h +++ b/include/apr_file_io.h @@ -111,6 +111,7 @@ typedef ap_int32_t ap_fileperms_t; 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 @@ struct ap_finfo_t { 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 @@ ap_status_t ap_fgets(char *str, int len, ap_file_t *thefile); B<Put the string into a specified file.> 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,10 +404,10 @@ ap_status_t ap_dupfile(ap_file_t **new_file, ap_file_t *old_file, ap_pool_t *p); =head1 ap_status_t ap_getfileinfo(ap_finfo_t *finfo, ap_file_t *thefile) -B<get the specified file's stats..> +B<get the specified file's stats.> 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 */ @@ -413,6 +415,24 @@ 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<set the specified file's permission bits.> + + 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); + +/* + =head1 ap_status_t ap_stat(ap_finfo_t *finfo, const char *fname, ap_pool_t *cont) B<get the specified file's stats. The file is specified by filename, instead of using a pre-opened file.> diff --git a/include/arch/unix/fileio.h b/include/arch/unix/fileio.h index 06e38ee84..c91bb453d 100644 --- a/include/arch/unix/fileio.h +++ b/include/arch/unix/fileio.h @@ -143,7 +143,9 @@ struct ap_dir_t { }; 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 */ |