s4
diff pwrap.c @ 546:768e80ef2b80
add group-add.sh
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Sat, 06 Apr 2019 21:32:10 +0900 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/pwrap.c Sat Apr 06 21:32:10 2019 +0900 1.3 @@ -0,0 +1,68 @@ 1.4 +#include <stdio.h> 1.5 +#include <stdlib.h> 1.6 +#include <sys/types.h> 1.7 +#include <unistd.h> 1.8 +#include <sys/stat.h> 1.9 +#include <string.h> 1.10 + 1.11 +#ifndef CGISCRIPT_PATH 1.12 +#define CGISCRIPT_PATH "./s4.cgi" 1.13 +#endif 1.14 + 1.15 +int main(int argc, char *argv[]) 1.16 +{ 1.17 + char *path=malloc(strlen(argv[0])); 1.18 + char *p; 1.19 + uid_t euid = geteuid(); 1.20 + struct stat st; 1.21 + if (0 == euid) { 1.22 + fputs("Do not call this program with suid 0\n", stderr); 1.23 + exit(0); 1.24 + } 1.25 + strcpy(path, argv[0]); 1.26 + p = strrchr(path, '/'); 1.27 + if (p) { 1.28 + *p = '\0'; 1.29 + } else { 1.30 + fputs("Cannot detect the directory where this program located.\n", stderr); 1.31 + exit(1); 1.32 + } 1.33 + 1.34 + if (-1 == chdir(path)) { 1.35 + fprintf(stderr, "Cannot chdir to %s\n", path); 1.36 + exit(2); 1.37 + } 1.38 + if (0 > stat(CGISCRIPT_PATH, &st)) { 1.39 + fprintf(stderr, "Cannot access %s\n", CGISCRIPT_PATH); 1.40 + exit(3); 1.41 + } 1.42 + if (st.st_uid != euid) { 1.43 + fputs("UID of cgi program mismatch\n", stderr); 1.44 + fputs("Do chown so that wrapper and cgi files' uid matches.\n", stderr); 1.45 + exit(4); 1.46 + } 1.47 + if (st.st_mode & (S_IWGRP | S_IWOTH)) { 1.48 + fputs("This program is writable for group/others.\n", stderr); 1.49 + fputs("Do chmod og-w for installed cgi-program.\n", stderr); 1.50 + exit(5); 1.51 + } 1.52 + if (0 > stat(".", &st)) { 1.53 + fputs("Cannot stat current directory\n", stderr); 1.54 + fputs("Please ensure installed directory is readable.\n", stderr); 1.55 + exit(6); 1.56 + } 1.57 +/* 1.58 + if (st.st_uid != euid) { 1.59 + fputs("UID of directory mismatch\n", stderr); 1.60 + fputs("Do chown so that wrapper and directorys' uid matches.\n", stderr); 1.61 + exit(7); 1.62 + } 1.63 +*/ 1.64 + if (st.st_mode & (S_IWGRP | S_IWOTH)) { 1.65 + fputs("This directory is writable for group/others.\n", stderr); 1.66 + fputs("Do chmod og-w for installed directory.\n", stderr); 1.67 + exit(8); 1.68 + } 1.69 + argv[0] = CGISCRIPT_PATH; 1.70 + execv(CGISCRIPT_PATH, argv); 1.71 +}