Mercurial > hgrepos > hgweb.cgi > after5
diff a5.c @ 18:399f24a71eb9 draft
Add required files.
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Sun, 01 Apr 2012 17:03:01 +0900 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/a5.c Sun Apr 01 17:03:01 2012 +0900 @@ -0,0 +1,58 @@ +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <unistd.h> +#include <sys/stat.h> +#include <string.h> + +#define AFTER5PATH "./after5.cgi" + +int main(int argc, char *argv[]) +{ + char *path=malloc(strlen(argv[0])); + char *p; + uid_t euid = geteuid(); + struct stat st; + if (0 == euid) { + fputs("Do not call this program with suid 0\n", stderr); + exit(0); + } + strcpy(path, argv[0]); + p = strrchr(path, '/'); + if (p) { + *p = '\0'; + } else { + fputs("Cannot detect the directory where this program located.\n", stderr); + exit(1); + } + + if (-1 == chdir(path)) { + fprintf(stderr, "Cannot chdir to %s\n", path); + exit(2); + } + if (0 > stat(AFTER5PATH, &st)) { + fprintf(stderr, "Cannot access %s\n", AFTER5PATH); + exit(3); + } + if (st.st_uid != euid) { + fputs("UID of cgi program mismatch\n", stderr); + fputs("Do chown so that wrapper and cgi files' uid matches.\n", stderr); + exit(4); + } + if (0 > stat(".", &st)) { + fputs("Cannot stat current directory\n", stderr); + fputs("Please ensure installed directory is readable.\n", stderr); + exit(5); + } + if (st.st_uid != euid) { + fputs("UID of directory mismatch\n", stderr); + fputs("Do chown so that wrapper and directorys' uid matches.\n", stderr); + exit(6); + } + if (st.st_mode & (S_IWGRP | S_IWOTH)) { + fputs("This directory is writable for group/others.\n", stderr); + fputs("Do chmod og-w for installed directory.\n", stderr); + exit(7); + } + execv("./after5.cgi", argv); +}