#include #include #include #include #include #include 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); }