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

nekral-guest at alioth.debian.org nekral-guest at alioth.debian.org
Mon Mar 16 23:20:43 UTC 2009


Author: nekral-guest
Date: 2009-03-16 23:20:43 +0000 (Mon, 16 Mar 2009)
New Revision: 2553

Added:
   debian/trunk/tests/common/Makefile
   debian/trunk/tests/common/rename_failure.c
Log:
Added interposition library necessary for the failures tests.


Added: debian/trunk/tests/common/Makefile
===================================================================
--- debian/trunk/tests/common/Makefile	                        (rev 0)
+++ debian/trunk/tests/common/Makefile	2009-03-16 23:20:43 UTC (rev 2553)
@@ -0,0 +1,4 @@
+all: rename_failure.so
+
+rename_failure.so: rename_failure.c
+	gcc -W -Wall -pedantic -g $< -shared -ldl -o $@

Added: debian/trunk/tests/common/rename_failure.c
===================================================================
--- debian/trunk/tests/common/rename_failure.c	                        (rev 0)
+++ debian/trunk/tests/common/rename_failure.c	2009-03-16 23:20:43 UTC (rev 2553)
@@ -0,0 +1,50 @@
+/* 
+ * gcc rename_failure.c -o rename_failure.so -shared -ldl 
+ * LD_PRELOAD=./rename_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 (*rename_type) (const char *old, const char *new);
+static rename_type next_rename;
+
+static const char *failure_path = NULL;
+
+int rename (const char *old, const char *new)
+{
+	if (NULL == next_rename)
+	{
+		next_rename = dlsym (RTLD_NEXT, "rename");
+		assert (NULL != next_rename);
+	}
+	if (NULL == failure_path) {
+		failure_path = getenv ("FAILURE_PATH");
+		if (NULL == failure_path) {
+			fputs ("No FAILURE_PATH defined\n", stderr);
+		}
+	}
+
+	if (   (NULL != new)
+	    && (NULL != failure_path)
+	    && (strcmp (new, failure_path) == 0))
+	{
+		fprintf (stderr, "rename FAILURE %s %s\n", old, new);
+		errno = EIO;
+		return -1;
+	}
+
+	return next_rename (old, new);
+}
+




More information about the Pkg-shadow-commits mailing list