diff options
Diffstat (limited to 'keyper.c')
| -rw-r--r-- | keyper.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/keyper.c b/keyper.c new file mode 100644 index 0000000..a3338c3 --- /dev/null +++ b/keyper.c @@ -0,0 +1,55 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <fcntl.h> +#include <sys/stat.h> + +static int check_fname(const char* fname) +{ + while (*fname) { + if (strchr("/.", *(fname++))) { + return 0; + } + } + return 1; +} + +static int dump_file(const char* fname) +{ + int fd = open(fname, O_RDONLY); + if (fd == -1) { + fprintf(stderr, "Failed to open %s\n", fname); + return 1; + } + char buf[1024]; + int buflen; + while ((buflen = read(fd, buf, sizeof(buf))) > 0) { + write(1, buf, buflen); + } + close(fd); + return 0; +} + +int main(int argc, char** argv) +{ + const char* file = getenv("KEYPER_FILE"); + const char* disable_file = getenv("KEYPER_DISABLE_FILE"); + + if (!disable_file) { + disable_file="keyper-disable"; + } + + if (!file) { + fprintf(stderr, "No KEYPER_FILE value.\n"); + return 1; + } + + struct stat statbuf; + if (!stat(disable_file, &statbuf)) { + fprintf(stderr, "Keyper disabled because %s exists.\n", disable_file); + return 127; + } + + return dump_file(file); +} |