aboutsummaryrefslogtreecommitdiffstats
path: root/guts
diff options
context:
space:
mode:
authorPeter Seebach <seebs@eee12.(none)>2010-04-05 18:25:30 -0500
committerPeter Seebach <peter.seebach@windriver.com>2010-04-26 17:13:12 -0700
commitd686759bcfe87a08336470666283c4b2ab6ad510 (patch)
tree2b3361e223e8c7dffbde7a7ed6dbed0fc777da0a /guts
parent9517843c85e733df325aabe24b0fb16cc1beaf94 (diff)
downloadpseudo-d686759bcfe87a08336470666283c4b2ab6ad510.tar.gz
pseudo-d686759bcfe87a08336470666283c4b2ab6ad510.tar.bz2
pseudo-d686759bcfe87a08336470666283c4b2ab6ad510.zip
Add lckpwdf()/ulckpwdf().
It's not enough to rely on the usual chroot() stuff affecting the file open, not least because these use the glibc-internal __open which is not currently intercepted, but also because we want to use the PSEUDO_PASSWD path when that's set but there's no chroot(). There's some extra magic in pseudo_etc_file to support these operations, since they can legitimately create a file rather than opening an existing one.
Diffstat (limited to 'guts')
-rw-r--r--guts/lckpwdf.c32
-rw-r--r--guts/ulckpwdf.c16
2 files changed, 48 insertions, 0 deletions
diff --git a/guts/lckpwdf.c b/guts/lckpwdf.c
new file mode 100644
index 0000000..b452ec0
--- /dev/null
+++ b/guts/lckpwdf.c
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2010 Wind River Systems; see
+ * guts/COPYRIGHT for information.
+ *
+ * static int
+ * wrap_lckpwdf(void) {
+ * int rc = -1;
+ */
+ rc = pseudo_pwd_lck_open();
+ if (rc != -1) {
+ struct flock lck = {
+ .l_type = F_RDLCK,
+ .l_whence = SEEK_SET,
+ .l_start = 0,
+ .l_len = 1
+ };
+ /* I don't really care whether this works. */
+ fcntl(rc, F_SETFD, FD_CLOEXEC);
+ /* Now lock it. */
+ alarm(15); /* magic number from man page */
+ rc = fcntl(rc, F_SETLKW, &lck);
+ alarm(0);
+ if (rc == -1) {
+ int save_errno = errno;
+ pseudo_pwd_lck_close();
+ errno = save_errno;
+ }
+ }
+
+/* return rc;
+ * }
+ */
diff --git a/guts/ulckpwdf.c b/guts/ulckpwdf.c
new file mode 100644
index 0000000..bdb6f42
--- /dev/null
+++ b/guts/ulckpwdf.c
@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2010 Wind River Systems; see
+ * guts/COPYRIGHT for information.
+ *
+ * static int
+ * wrap_ulckpwdf(void) {
+ * int rc = -1;
+ */
+
+ /* lock is cleared automatically on close */
+ pseudo_pwd_lck_close();
+ rc = 0;
+
+/* return rc;
+ * }
+ */