diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-06 02:22:06 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-06 02:22:06 +0000 |
commit | 741c1ef7a4f2ac316ad6e557ddbe03023413478d (patch) | |
tree | 38890f681daa26c57e865b4feca10d0ca53e1046 /tests/common/unlink_failure.c | |
parent | Initial commit. (diff) | |
download | shadow-741c1ef7a4f2ac316ad6e557ddbe03023413478d.tar.xz shadow-741c1ef7a4f2ac316ad6e557ddbe03023413478d.zip |
Adding upstream version 1:4.5.upstream/1%4.5upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | tests/common/unlink_failure.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/common/unlink_failure.c b/tests/common/unlink_failure.c new file mode 100644 index 0000000..2281c8a --- /dev/null +++ b/tests/common/unlink_failure.c @@ -0,0 +1,51 @@ +/* + * gcc unlink_failure.c -o unlink_failure.so -shared -ldl + * LD_PRELOAD=./unlink_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> +#include <unistd.h> + + +typedef int (*unlink_type) (const char *path); +static unlink_type next_unlink; + +static const char *failure_path = NULL; + +int unlink (const char *path) +{ + if (NULL == next_unlink) + { + next_unlink = dlsym (RTLD_NEXT, "unlink"); + assert (NULL != next_unlink); + } + 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, "unlink FAILURE %s\n", path); + errno = EBUSY; + return -1; + } + + return next_unlink (path); +} + |