aboutsummaryrefslogtreecommitdiffstats
path: root/pseudo_util.c
diff options
context:
space:
mode:
authorPeter Seebach <seebs@eee12.(none)>2010-03-30 12:49:18 -0500
committerPeter Seebach <seebs@eee12.(none)>2010-03-30 12:57:01 -0500
commit35e89652b7d51f2246ee9a8de7592b19f9e6125d (patch)
tree3d128f874cb48c9f06948072ed674cd2452da3ca /pseudo_util.c
parentfa580977cc4fa8b58a47c483c1a59df66645a120 (diff)
downloadpseudo-35e89652b7d51f2246ee9a8de7592b19f9e6125d.tar.gz
pseudo-35e89652b7d51f2246ee9a8de7592b19f9e6125d.tar.bz2
pseudo-35e89652b7d51f2246ee9a8de7592b19f9e6125d.zip
Fix up group/password file handling and file opens.
Spotted some glibc extensions to file modes, altered fopen logic. Fix handling for the case where the underlying pseudo_pwd_fd or pseudo_grp_fd are closed.
Diffstat (limited to 'pseudo_util.c')
-rw-r--r--pseudo_util.c48
1 files changed, 27 insertions, 21 deletions
diff --git a/pseudo_util.c b/pseudo_util.c
index 8af3020..2cf6585 100644
--- a/pseudo_util.c
+++ b/pseudo_util.c
@@ -588,29 +588,35 @@ pseudo_sys_path_max(void) {
int
pseudo_access_fopen(const char *mode) {
int access = 0;
- switch (*mode) {
- case 'a':
- access |= (PSA_APPEND | PSA_WRITE);
- if (mode[1] == '+' || (mode[1] == 'b' && mode[2] == '+'))
+ for (; *mode; ++mode) {
+ switch (*mode) {
+ case 'a':
+ access |= (PSA_APPEND | PSA_WRITE);
+ break;
+ case 'r':
access |= PSA_READ;
- break;
- case 'r':
- access |= PSA_READ;
- if (mode[1] == '+' || (mode[1] == 'b' && mode[2] == '+'))
+ break;
+ case 'w':
access |= PSA_WRITE;
- break;
- case 'w':
- access |= PSA_WRITE;
- if (mode[1] == '+' || (mode[1] == 'b' && mode[2] == '+'))
- access |= PSA_READ;
- break;
- /* special case */
- case 'x':
- access |= PSA_EXEC;
- break;
- default:
- access = -1;
- break;
+ break;
+ case 'x':
+ /* special case -- note that this conflicts with a
+ * rarely-used glibc extension
+ */
+ access |= PSA_EXEC;
+ break;
+ case 'b': /* binary mode */
+ break;
+ case 'c': case 'e': case 'm': /* glibc extensions */
+ break;
+ case '+':
+ /* one of these will already be set, presumably */
+ access |= (PSA_READ | PSA_WRITE);
+ break;
+ default:
+ access = -1;
+ break;
+ }
}
return access;
}