s4

view pwrap.c @ 1037:634fee6a6bd2

Add row number to title attribute after sort.
author HIROSE Yuuji <yuuji@gentei.org>
date Wed, 06 Mar 2024 09:55:20 +0900
parents
children
line source
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>
8 #ifndef CGISCRIPT_PATH
9 #define CGISCRIPT_PATH "./s4.cgi"
10 #endif
12 int main(int argc, char *argv[])
13 {
14 char *path=malloc(strlen(argv[0]));
15 char *p;
16 uid_t euid = geteuid();
17 struct stat st;
18 if (0 == euid) {
19 fputs("Do not call this program with suid 0\n", stderr);
20 exit(0);
21 }
22 strcpy(path, argv[0]);
23 p = strrchr(path, '/');
24 if (p) {
25 *p = '\0';
26 } else {
27 fputs("Cannot detect the directory where this program located.\n", stderr);
28 exit(1);
29 }
31 if (-1 == chdir(path)) {
32 fprintf(stderr, "Cannot chdir to %s\n", path);
33 exit(2);
34 }
35 if (0 > stat(CGISCRIPT_PATH, &st)) {
36 fprintf(stderr, "Cannot access %s\n", CGISCRIPT_PATH);
37 exit(3);
38 }
39 if (st.st_uid != euid) {
40 fputs("UID of cgi program mismatch\n", stderr);
41 fputs("Do chown so that wrapper and cgi files' uid matches.\n", stderr);
42 exit(4);
43 }
44 if (st.st_mode & (S_IWGRP | S_IWOTH)) {
45 fputs("This program is writable for group/others.\n", stderr);
46 fputs("Do chmod og-w for installed cgi-program.\n", stderr);
47 exit(5);
48 }
49 if (0 > stat(".", &st)) {
50 fputs("Cannot stat current directory\n", stderr);
51 fputs("Please ensure installed directory is readable.\n", stderr);
52 exit(6);
53 }
54 /*
55 if (st.st_uid != euid) {
56 fputs("UID of directory mismatch\n", stderr);
57 fputs("Do chown so that wrapper and directorys' uid matches.\n", stderr);
58 exit(7);
59 }
60 */
61 if (st.st_mode & (S_IWGRP | S_IWOTH)) {
62 fputs("This directory is writable for group/others.\n", stderr);
63 fputs("Do chmod og-w for installed directory.\n", stderr);
64 exit(8);
65 }
66 argv[0] = CGISCRIPT_PATH;
67 execv(CGISCRIPT_PATH, argv);
68 }