comparison 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
comparison
equal deleted inserted replaced
17:904bbce89e71 18:399f24a71eb9
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/types.h>
4 #include <unistd.h>
5 #include <sys/stat.h>
6 #include <string.h>
7
8 #define AFTER5PATH "./after5.cgi"
9
10 int main(int argc, char *argv[])
11 {
12 char *path=malloc(strlen(argv[0]));
13 char *p;
14 uid_t euid = geteuid();
15 struct stat st;
16 if (0 == euid) {
17 fputs("Do not call this program with suid 0\n", stderr);
18 exit(0);
19 }
20 strcpy(path, argv[0]);
21 p = strrchr(path, '/');
22 if (p) {
23 *p = '\0';
24 } else {
25 fputs("Cannot detect the directory where this program located.\n", stderr);
26 exit(1);
27 }
28
29 if (-1 == chdir(path)) {
30 fprintf(stderr, "Cannot chdir to %s\n", path);
31 exit(2);
32 }
33 if (0 > stat(AFTER5PATH, &st)) {
34 fprintf(stderr, "Cannot access %s\n", AFTER5PATH);
35 exit(3);
36 }
37 if (st.st_uid != euid) {
38 fputs("UID of cgi program mismatch\n", stderr);
39 fputs("Do chown so that wrapper and cgi files' uid matches.\n", stderr);
40 exit(4);
41 }
42 if (0 > stat(".", &st)) {
43 fputs("Cannot stat current directory\n", stderr);
44 fputs("Please ensure installed directory is readable.\n", stderr);
45 exit(5);
46 }
47 if (st.st_uid != euid) {
48 fputs("UID of directory mismatch\n", stderr);
49 fputs("Do chown so that wrapper and directorys' uid matches.\n", stderr);
50 exit(6);
51 }
52 if (st.st_mode & (S_IWGRP | S_IWOTH)) {
53 fputs("This directory is writable for group/others.\n", stderr);
54 fputs("Do chmod og-w for installed directory.\n", stderr);
55 exit(7);
56 }
57 execv("./after5.cgi", argv);
58 }

yatex.org