[Pkg-shadow-commits] r3510 - debian/trunk/tests/common

Nicolas FRANÇOIS nekral-guest at alioth.debian.org
Sun Oct 16 14:24:39 UTC 2011


Author: nekral-guest
Date: 2011-10-16 14:24:39 +0000 (Sun, 16 Oct 2011)
New Revision: 3510

Added:
   debian/trunk/tests/common/fopen_failure.c
   debian/trunk/tests/common/open_RDONLY_failure.c
Log:
Add 2 other open failure libraries.


Added: debian/trunk/tests/common/fopen_failure.c
===================================================================
--- debian/trunk/tests/common/fopen_failure.c	                        (rev 0)
+++ debian/trunk/tests/common/fopen_failure.c	2011-10-16 14:24:39 UTC (rev 3510)
@@ -0,0 +1,46 @@
+/* 
+ * gcc fopen_failure.c -o fopen_failure.so -shared -ldl 
+ * LD_PRELOAD=./fopen_failure.so FAILURE_PATH=/etc/shadow ./test /etc/shadow
+ */
+
+#define _GNU_SOURCE
+#include <dlfcn.h>
+#include <errno.h>
+#include <assert.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+
+typedef FILE * (*fopen_type) (const char *path, const char *mode);
+static fopen_type next_fopen;
+
+static const char *failure_path = NULL;
+
+FILE *fopen64 (const char *path, const char *mode)
+{
+printf ("fopen64(%s, %s)\n", path, mode);
+	if (NULL == next_fopen)
+	{
+		next_fopen = dlsym (RTLD_NEXT, "fopen64");
+		assert (NULL != next_fopen);
+	}
+	if (NULL == failure_path) {
+		failure_path = getenv ("FAILURE_PATH");
+		if (NULL == failure_path) {
+			fputs ("No FAILURE_PATH defined\n", stderr);
+		}
+	}
+
+	if (   (NULL != path)
+	    && (NULL != failure_path)
+	    && (strcmp (path, failure_path) == 0))
+	{
+		fprintf (stderr, "fopen64 FAILURE %s %s ...\n", path, mode);
+		errno = EIO;
+		return NULL;
+	}
+
+	return next_fopen (path, mode);
+}
+

Added: debian/trunk/tests/common/open_RDONLY_failure.c
===================================================================
--- debian/trunk/tests/common/open_RDONLY_failure.c	                        (rev 0)
+++ debian/trunk/tests/common/open_RDONLY_failure.c	2011-10-16 14:24:39 UTC (rev 3510)
@@ -0,0 +1,51 @@
+/* 
+ * gcc open_RDONLY_failure.c -o open_RDONLY_failure.so -shared -ldl 
+ * LD_PRELOAD=./open_RDONLY_failure.so FAILURE_PATH=/etc/shadow ./test /etc/shadow
+ */
+
+#define _GNU_SOURCE
+#include <dlfcn.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdarg.h>
+#include <fcntl.h>
+#include <string.h>
+#include <errno.h>
+#include <assert.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+
+typedef int (*open_type) (const char *pathname, int flag, ...);
+static open_type next_open64;
+
+static const char *failure_path = NULL;
+
+int open64 (const char *pathname, int flag, ...)
+{
+	if (NULL == next_open64)
+	{
+		next_open64 = dlsym (RTLD_NEXT, "open64");
+		assert (NULL != next_open64);
+	}
+	if (NULL == failure_path) {
+		failure_path = getenv ("FAILURE_PATH");
+		if (NULL == failure_path) {
+			fputs ("No FAILURE_PATH defined\n", stderr);
+		}
+	}
+
+	if (   (NULL != pathname)
+	    && ((flag & O_ACCMODE) == O_RDONLY)
+	    && (NULL != failure_path)
+	    && (strcmp (pathname, failure_path) == 0))
+	{
+		fprintf (stderr, "open FAILURE %s %x ...\n", pathname, flag);
+		errno = EIO;
+		return -1;
+	}
+
+	return next_open64 (pathname, flag);
+}
+




More information about the Pkg-shadow-commits mailing list