aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Seebach <peter.seebach@windriver.com>2014-05-27 14:19:47 -0500
committerPeter Seebach <peter.seebach@windriver.com>2014-05-27 14:19:47 -0500
commit2f71a021b725c1aa415439209a89327f0b997d02 (patch)
treee8888f8164198ef363688558cd9b9953b5c0a158
parentc98e4f43b5d6499748a5057134408f4ba4854fb4 (diff)
downloadpseudo-2f71a021b725c1aa415439209a89327f0b997d02.tar.gz
pseudo-2f71a021b725c1aa415439209a89327f0b997d02.tar.bz2
pseudo-2f71a021b725c1aa415439209a89327f0b997d02.zip
Honor umask
We used to rely on filesystem operations to apply the umask when appropriate, but when we started masking out 022, that stopped working. Start watching umask.
-rw-r--r--ChangeLog.txt4
-rwxr-xr-xmakewrappers1
-rw-r--r--ports/darwin/guts/open.c3
-rw-r--r--ports/linux/guts/__xmknodat.c3
-rw-r--r--ports/linux/guts/openat.c3
-rw-r--r--ports/unix/guts/mkdirat.c3
-rw-r--r--ports/unix/guts/mknodat.c3
-rw-r--r--ports/unix/guts/umask.c14
-rw-r--r--ports/unix/wrapfuncs.in1
-rw-r--r--pseudo_client.c5
-rw-r--r--pseudo_client.h4
11 files changed, 43 insertions, 1 deletions
diff --git a/ChangeLog.txt b/ChangeLog.txt
index 827ff7a..cffc2e9 100644
--- a/ChangeLog.txt
+++ b/ChangeLog.txt
@@ -1,3 +1,7 @@
+2014-05-27:
+ * (seebs) start noticing umask, mask it out from open or mkdir
+ calls rather than relying on underlying open/mkdir to do it.
+
2014-05-16:
* (seebs) fchmodat: don't drop flags, report failures, to improve
compatibility/consistency. Cache the knowledge that
diff --git a/makewrappers b/makewrappers
index f487887..46aeb44 100755
--- a/makewrappers
+++ b/makewrappers
@@ -204,6 +204,7 @@ class Function:
'uid_t': '0',
'int': '-1',
'long': '-1',
+ 'mode_t': '0',
'ssize_t': '-1'
}
diff --git a/ports/darwin/guts/open.c b/ports/darwin/guts/open.c
index 8680e20..afe19a2 100644
--- a/ports/darwin/guts/open.c
+++ b/ports/darwin/guts/open.c
@@ -9,6 +9,9 @@
struct stat buf = { };
int existed = 1;
int save_errno;
+
+ /* mask out mode bits appropriately */
+ mode = mode & ~pseudo_umask;
#ifdef PSEUDO_FORCE_ASYNCH
flags &= ~O_SYNC;
#endif
diff --git a/ports/linux/guts/__xmknodat.c b/ports/linux/guts/__xmknodat.c
index 59b4f2f..0888b8a 100644
--- a/ports/linux/guts/__xmknodat.c
+++ b/ports/linux/guts/__xmknodat.c
@@ -9,6 +9,9 @@
pseudo_msg_t *msg;
struct stat64 buf;
+ /* mask out mode bits appropriately */
+ mode = mode & ~pseudo_umask;
+
/* we don't use underlying call, so _ver is irrelevant to us */
(void) ver;
diff --git a/ports/linux/guts/openat.c b/ports/linux/guts/openat.c
index 1225368..87fa466 100644
--- a/ports/linux/guts/openat.c
+++ b/ports/linux/guts/openat.c
@@ -10,6 +10,9 @@
int existed = 1;
int save_errno;
+ /* mask out mode bits appropriately */
+ mode = mode & ~pseudo_umask;
+
#ifdef PSEUDO_NO_REAL_AT_FUNCTIONS
if (dirfd != AT_FDCWD) {
errno = ENOSYS;
diff --git a/ports/unix/guts/mkdirat.c b/ports/unix/guts/mkdirat.c
index 5f97ab5..dceedeb 100644
--- a/ports/unix/guts/mkdirat.c
+++ b/ports/unix/guts/mkdirat.c
@@ -11,6 +11,9 @@
errno = ENOSYS;
return -1;
}
+ /* mask out mode bits appropriately */
+ mode = mode & ~pseudo_umask;
+
rc = real_mkdir(path, PSEUDO_FS_MODE(mode, 1));
#else
rc = real_mkdirat(dirfd, path, PSEUDO_FS_MODE(mode, 1));
diff --git a/ports/unix/guts/mknodat.c b/ports/unix/guts/mknodat.c
index 6fd5b42..5d8d47c 100644
--- a/ports/unix/guts/mknodat.c
+++ b/ports/unix/guts/mknodat.c
@@ -10,6 +10,9 @@
PSEUDO_STATBUF buf;
int save_errno = errno;
+ /* mask out mode bits appropriately */
+ mode = mode & ~pseudo_umask;
+
#ifdef PSEUDO_NO_REAL_AT_FUNCTIONS
if (dirfd != AT_FDCWD) {
errno = ENOSYS;
diff --git a/ports/unix/guts/umask.c b/ports/unix/guts/umask.c
new file mode 100644
index 0000000..6b060d3
--- /dev/null
+++ b/ports/unix/guts/umask.c
@@ -0,0 +1,14 @@
+/*
+ * Copyright (c) 2014 Wind River Systems; see
+ * guts/COPYRIGHT for information.
+ *
+ * mode_t umask(mode_t mask)
+ * mode_t rc = 0;
+ */
+
+ pseudo_umask = mask;
+ rc = real_umask(mask);
+
+/* return rc;
+ * }
+ */
diff --git a/ports/unix/wrapfuncs.in b/ports/unix/wrapfuncs.in
index 8460a65..e0e9739 100644
--- a/ports/unix/wrapfuncs.in
+++ b/ports/unix/wrapfuncs.in
@@ -67,3 +67,4 @@ void sync(void); /* async_skip= */
int syncfs(int fd); /* async_skip=0 */
int sync_file_range(int fd, off64_t offset, off64_t nbytes, unsigned int flags); /* async_skip=0 */
int msync(void *addr, size_t length, int flags); /* async_skip=0 */
+mode_t umask(mode_t mask);
diff --git a/pseudo_client.c b/pseudo_client.c
index 39f9641..d52f755 100644
--- a/pseudo_client.c
+++ b/pseudo_client.c
@@ -71,6 +71,8 @@ int pseudo_disabled = 0;
int pseudo_allow_fsync = 0;
static int pseudo_local_only = 0;
+int pseudo_umask = 022;
+
static char **fd_paths = NULL;
static int nfds = 0;
static int messages = 0;
@@ -224,6 +226,9 @@ pseudo_init_client(void) {
if (!pseudo_disabled && !pseudo_inited) {
char *pseudo_path = 0;
+ pseudo_umask = umask(022);
+ umask(pseudo_umask);
+
pseudo_path = pseudo_prefix_path(NULL);
if (pseudo_prefix_dir_fd == -1) {
if (pseudo_path) {
diff --git a/pseudo_client.h b/pseudo_client.h
index ecb13a6..5bf820e 100644
--- a/pseudo_client.h
+++ b/pseudo_client.h
@@ -72,6 +72,8 @@ extern char *pseudo_passwd;
extern size_t pseudo_chroot_len;
extern int pseudo_nosymlinkexp;
+extern int pseudo_umask;
+
/* Root can read and write files, and enter directories which have no
* read, write, or execute permissions. (But can't execute files without
* execute permissions!)
@@ -85,6 +87,6 @@ extern int pseudo_nosymlinkexp;
* None of this will behave very sensibly if umask has 0700 bits in it;
* this is a known limitation.
*/
-#define PSEUDO_FS_MODE(mode, isdir) ((((mode) | S_IRUSR | S_IWUSR | ((isdir) ? S_IXUSR : 0)) & ~(S_IWGRP | S_IWOTH)) & ~(S_IWOTH | S_IWGRP))
+#define PSEUDO_FS_MODE(mode, isdir) (((mode) | S_IRUSR | S_IWUSR | ((isdir) ? S_IXUSR : 0)) & ~(S_IWGRP | S_IWOTH))
#define PSEUDO_DB_MODE(fs_mode, user_mode) (((fs_mode) & ~0722) | ((user_mode & 0722)))