1
0
mirror of https://github.com/gophernicus/gophernicus.git synced 2024-11-03 04:27:17 -05:00

It compiles and runs!!

This commit is contained in:
fosslinux 2019-10-19 18:28:37 +11:00
parent 861a32142d
commit 5bba12cd85
6 changed files with 42 additions and 2 deletions

View File

@ -54,7 +54,7 @@ IPCRM = /usr/bin/ipcrm
# Platform support, compatible with both BSD and GNU make # Platform support, compatible with both BSD and GNU make
# #
all: all:
@case `uname` in \ case `uname` in \
Darwin) $(MAKE) ROOT="$(OSXROOT)" DESTDIR="$(OSXDEST)" $(BINARY); ;; \ Darwin) $(MAKE) ROOT="$(OSXROOT)" DESTDIR="$(OSXDEST)" $(BINARY); ;; \
Haiku) $(MAKE) EXTRA_LIBS="-lnetwork" $(BINARY); ;; \ Haiku) $(MAKE) EXTRA_LIBS="-lnetwork" $(BINARY); ;; \
*) if [ -f "/usr/include/tcpd.h" ]; then $(MAKE) withwrap; else $(MAKE) $(BINARY); fi; ;; \ *) if [ -f "/usr/include/tcpd.h" ]; then $(MAKE) withwrap; else $(MAKE) $(BINARY); fi; ;; \

BIN
bin2c.exe Normal file

Binary file not shown.

14
file.c
View File

@ -238,7 +238,11 @@ void server_status(state *st, shm_state *shm, int shmid)
/* /*
* Handle /caps.txt * Handle /caps.txt
*/ */
#ifdef HAVE_SHMEM
void caps_txt(state *st, shm_state *shm) void caps_txt(state *st, shm_state *shm)
#else
void caps_txt(state *st)
#endif
{ {
/* Log the request */ /* Log the request */
#ifdef HAVE_SYSLOG #ifdef HAVE_SYSLOG
@ -425,7 +429,12 @@ void gopher_file(state *st)
snprintf(buf, sizeof(buf), "%s/%s", st->filter_dir, c + 1); snprintf(buf, sizeof(buf), "%s/%s", st->filter_dir, c + 1);
/* Filter file through the script */ /* Filter file through the script */
/* Skip this second check on Windows */
#ifdef _WIN32
if (stat(buf, &file) == OK)
#else
if (stat(buf, &file) == OK && (file.st_mode & S_IXOTH)) if (stat(buf, &file) == OK && (file.st_mode & S_IXOTH))
#endif
run_cgi(st, buf, st->req_realpath); run_cgi(st, buf, st->req_realpath);
} }
@ -434,7 +443,12 @@ void gopher_file(state *st)
snprintf(buf, sizeof(buf), "%s/%c", st->filter_dir, st->req_filetype); snprintf(buf, sizeof(buf), "%s/%c", st->filter_dir, st->req_filetype);
/* Filter file through the script */ /* Filter file through the script */
/* Skip this second check on Windows */
#ifdef _WIN32
if (stat(buf, &file) == OK)
#else
if (stat(buf, &file) == OK && (file.st_mode & S_IXOTH)) if (stat(buf, &file) == OK && (file.st_mode & S_IXOTH))
#endif
run_cgi(st, buf, st->req_realpath); run_cgi(st, buf, st->req_realpath);
} }

View File

@ -315,6 +315,7 @@ void selector_to_path(state *st)
*/ */
char *get_local_address(void) char *get_local_address(void)
{ {
#ifndef _WIN32
#ifdef HAVE_IPv4 #ifdef HAVE_IPv4
struct sockaddr_in addr; struct sockaddr_in addr;
socklen_t addrsize = sizeof(addr); socklen_t addrsize = sizeof(addr);
@ -344,6 +345,7 @@ char *get_local_address(void)
else return address; else return address;
} }
} }
#endif
#endif #endif
/* Nothing works... I'm out of ideas */ /* Nothing works... I'm out of ideas */
@ -356,6 +358,7 @@ char *get_local_address(void)
*/ */
char *get_peer_address(void) char *get_peer_address(void)
{ {
#ifndef _WIN32
#ifdef HAVE_IPv4 #ifdef HAVE_IPv4
struct sockaddr_in addr; struct sockaddr_in addr;
socklen_t addrsize = sizeof(addr); socklen_t addrsize = sizeof(addr);
@ -389,6 +392,7 @@ char *get_peer_address(void)
else return address; else return address;
} }
} }
#endif
#endif #endif
/* Nothing works... I'm out of ideas */ /* Nothing works... I'm out of ideas */
@ -429,8 +433,10 @@ void init_state(state *st)
if ((c = getenv("HOSTNAME"))) if ((c = getenv("HOSTNAME")))
sstrlcpy(st->server_host, c); sstrlcpy(st->server_host, c);
#ifndef _WIN32
else if ((gethostname(buf, sizeof(buf))) != ERROR) else if ((gethostname(buf, sizeof(buf))) != ERROR)
sstrlcpy(st->server_host, buf); sstrlcpy(st->server_host, buf);
#endif
st->server_port = DEFAULT_PORT; st->server_port = DEFAULT_PORT;
st->server_tls_port = DEFAULT_TLS_PORT; st->server_tls_port = DEFAULT_TLS_PORT;
@ -528,7 +534,12 @@ int main(int argc, char *argv[])
setlocale(LC_TIME, DATE_LOCALE); setlocale(LC_TIME, DATE_LOCALE);
#endif #endif
init_state(&st); init_state(&st);
#ifdef _WIN32
/* Windows dosen't have getppid() */
srand(time(NULL) / getpid());
#else
srand(time(NULL) / (getpid() + getppid())); srand(time(NULL) / (getpid() + getppid()));
#endif
/* Handle command line arguments */ /* Handle command line arguments */
parse_args(&st, argc, argv); parse_args(&st, argc, argv);
@ -838,10 +849,13 @@ get_selector:
st.req_filesize = file.st_size; st.req_filesize = file.st_size;
/* Everyone must have read access but no write access */ /* Everyone must have read access but no write access */
/* Skip this check on Windows */
#ifndef _WIN32
if ((file.st_mode & S_IROTH) == 0) if ((file.st_mode & S_IROTH) == 0)
die(&st, ERR_ACCESS, "File or directory not world-readable"); die(&st, ERR_ACCESS, "File or directory not world-readable");
if ((file.st_mode & S_IWOTH) != 0) if ((file.st_mode & S_IWOTH) != 0)
die(&st, ERR_ACCESS, "File or directory world-writeable"); die(&st, ERR_ACCESS, "File or directory world-writeable");
#endif
/* If stat said it was a dir then it's a menu */ /* If stat said it was a dir then it's a menu */
if ((file.st_mode & S_IFMT) == S_IFDIR) st.req_filetype = TYPE_MENU; if ((file.st_mode & S_IFMT) == S_IFDIR) st.req_filetype = TYPE_MENU;

BIN
gophernicus.exe Normal file

Binary file not shown.

14
menu.c
View File

@ -171,8 +171,11 @@ void vhostlist(state *st)
if (!strchr(dir[i].name, '.')) continue; if (!strchr(dir[i].name, '.')) continue;
/* We only want world-readable directories */ /* We only want world-readable directories */
/* Skip check on Windows */
#ifndef _WIN32
if ((dir[i].mode & S_IROTH) == 0) continue; if ((dir[i].mode & S_IROTH) == 0) continue;
if ((dir[i].mode & S_IFMT) != S_IFDIR) continue; if ((dir[i].mode & S_IFMT) != S_IFDIR) continue;
#endif
/* Generate display string for vhost */ /* Generate display string for vhost */
snprintf(buf, sizeof(buf), VHOST_FORMAT, dir[i].name); snprintf(buf, sizeof(buf), VHOST_FORMAT, dir[i].name);
@ -288,6 +291,8 @@ int gophermap(state *st, char *mapfile, int depth)
if (depth > 4) return OK; if (depth > 4) return OK;
/* Try to figure out whether the map is executable */ /* Try to figure out whether the map is executable */
/* Executable gophermaps not yet supported on Windows */
#ifndef _WIN32
if (stat(mapfile, &file) == OK) { if (stat(mapfile, &file) == OK) {
if ((file.st_mode & S_IXOTH)) { if ((file.st_mode & S_IXOTH)) {
#ifdef HAVE_POPEN #ifdef HAVE_POPEN
@ -307,6 +312,9 @@ int gophermap(state *st, char *mapfile, int depth)
#endif #endif
exe = TRUE; exe = TRUE;
} }
#else
exe = FALSE;
#endif
/* Debug output */ /* Debug output */
#ifdef HAVE_SYSLOG #ifdef HAVE_SYSLOG
@ -558,9 +566,13 @@ void gopher_menu(state *st)
snprintf(pathname, sizeof(pathname), "%s/%s", snprintf(pathname, sizeof(pathname), "%s/%s",
st->req_realpath, dir[i].name); st->req_realpath, dir[i].name);
/* Skip dotfiles and non world-readables */ /* Skip dotfiles */
if (dir[i].name[0] == '.') continue; if (dir[i].name[0] == '.') continue;
/* Skip non world-readables */
/* Skip check on Windows */
#ifndef _WIN32
if ((dir[i].mode & S_IROTH) == 0) continue; if ((dir[i].mode & S_IROTH) == 0) continue;
#endif
/* Skip gophermaps and tags (but not dirs) */ /* Skip gophermaps and tags (but not dirs) */
if ((dir[i].mode & S_IFMT) != S_IFDIR) { if ((dir[i].mode & S_IFMT) != S_IFDIR) {