mirror of
https://github.com/gophernicus/gophernicus.git
synced 2024-11-03 04:27:17 -05:00
still-broken windows port; still need to implement winsock for sucessful build
This commit is contained in:
parent
34cbd01ac3
commit
861a32142d
2
Makefile
2
Makefile
@ -92,6 +92,8 @@ functions.h:
|
||||
grep -v "strlc" | \
|
||||
grep -v "[a-z]:" | \
|
||||
sed -e "s/ =.*$$//" -e "s/ *$$/;/" >> $@
|
||||
sed -i '/shm_state/i #ifdef HAVE_SHMEM' functions.h
|
||||
sed -i '/shm_state/a #endif' functions.h
|
||||
@echo
|
||||
|
||||
bin2c: bin2c.c
|
||||
|
16
file.c
16
file.c
@ -40,7 +40,9 @@ void send_binary_file(state *st)
|
||||
int fd;
|
||||
off_t offset = 0;
|
||||
|
||||
#ifdef HAVE_SYSLOG
|
||||
if (st->debug) syslog(LOG_INFO, "outputting binary file \"%s\"", st->req_realpath);
|
||||
#endif
|
||||
|
||||
if ((fd = open(st->req_realpath, O_RDONLY)) == ERROR) return;
|
||||
sendfile(1, fd, &offset, st->req_filesize);
|
||||
@ -52,7 +54,9 @@ void send_binary_file(state *st)
|
||||
char buf[BUFSIZE];
|
||||
int bytes;
|
||||
|
||||
#ifdef HAVE_SYSLOG
|
||||
if (st->debug) syslog(LOG_INFO, "outputting binary file \"%s\"", st->req_realpath);
|
||||
#endif
|
||||
|
||||
if ((fp = fopen(st->req_realpath , "r")) == NULL) return;
|
||||
while ((bytes = fread(buf, 1, sizeof(buf), fp)) > 0)
|
||||
@ -72,7 +76,9 @@ void send_text_file(state *st)
|
||||
char out[BUFSIZE];
|
||||
int line;
|
||||
|
||||
#ifdef HAVE_SYSLOG
|
||||
if (st->debug) syslog(LOG_INFO, "outputting text file \"%s\"", st->req_realpath);
|
||||
#endif
|
||||
if ((fp = fopen(st->req_realpath , "r")) == NULL) return;
|
||||
|
||||
/* Loop through the file line by line */
|
||||
@ -119,6 +125,7 @@ void url_redirect(state *st)
|
||||
die(st, ERR_ACCESS, "Refusing to HTTP redirect unsafe protocols");
|
||||
|
||||
/* Log the redirect */
|
||||
#ifdef HAVE_SYSLOG
|
||||
if (st->opt_syslog) {
|
||||
syslog(LOG_INFO, "request for \"gopher%s://%s:%i/h%s\" from %s",
|
||||
(st->server_port == st->server_tls_port ? "s" : ""),
|
||||
@ -127,6 +134,7 @@ void url_redirect(state *st)
|
||||
st->req_selector,
|
||||
st->req_remote_addr);
|
||||
}
|
||||
#endif
|
||||
log_combined(st, HTTP_OK);
|
||||
|
||||
/* Output HTML */
|
||||
@ -156,6 +164,7 @@ void server_status(state *st, shm_state *shm, int shmid)
|
||||
int i;
|
||||
|
||||
/* Log the request */
|
||||
#ifdef HAVE_SYSLOG
|
||||
if (st->opt_syslog) {
|
||||
syslog(LOG_INFO, "request for \"gopher%s://%s:%i/0" SERVER_STATUS "\" from %s",
|
||||
(st->server_port == st->server_tls_port ? "s" : ""),
|
||||
@ -163,6 +172,7 @@ void server_status(state *st, shm_state *shm, int shmid)
|
||||
st->server_port,
|
||||
st->req_remote_addr);
|
||||
}
|
||||
#endif
|
||||
log_combined(st, HTTP_OK);
|
||||
|
||||
/* Quit if shared memory isn't initialized yet */
|
||||
@ -231,6 +241,7 @@ void server_status(state *st, shm_state *shm, int shmid)
|
||||
void caps_txt(state *st, shm_state *shm)
|
||||
{
|
||||
/* Log the request */
|
||||
#ifdef HAVE_SYSLOG
|
||||
if (st->opt_syslog) {
|
||||
syslog(LOG_INFO, "request for \"gopher%s://%s:%i/0" CAPS_TXT "\" from %s",
|
||||
(st->server_port == st->server_tls_port ? "s" : ""),
|
||||
@ -238,6 +249,7 @@ void caps_txt(state *st, shm_state *shm)
|
||||
st->server_port,
|
||||
st->req_remote_addr);
|
||||
}
|
||||
#endif
|
||||
log_combined(st, HTTP_OK);
|
||||
|
||||
/* Update counters */
|
||||
@ -370,12 +382,16 @@ void run_cgi(state *st, char *script, char *arg)
|
||||
if (st->opt_exec) {
|
||||
|
||||
/* Setup environment & execute the binary */
|
||||
#ifdef HAVE_SYSLOG
|
||||
if (st->debug) syslog(LOG_INFO, "executing script \"%s\"", script);
|
||||
#endif
|
||||
|
||||
setenv_cgi(st, script);
|
||||
execl(script, script, arg, NULL);
|
||||
}
|
||||
#ifdef HAVE_SYSLOG
|
||||
else if (st->debug) syslog(LOG_INFO, "script \"%s\" was blocked by -nx", script);
|
||||
#endif
|
||||
|
||||
/* Didn't work - die */
|
||||
die(st, ERR_ACCESS, NULL);
|
||||
|
@ -119,10 +119,12 @@ void die(state *st, char *message, char *description)
|
||||
if (description == NULL) description = strerror(en);
|
||||
|
||||
/* Log the error */
|
||||
#ifdef HAVE_SYSLOG
|
||||
if (st->opt_syslog) {
|
||||
syslog(LOG_ERR, "error \"%s\" for request \"%s\" from %s",
|
||||
description, st->req_selector, st->req_remote_addr);
|
||||
}
|
||||
#endif
|
||||
log_combined(st, HTTP_404);
|
||||
|
||||
/* Handle menu errors */
|
||||
@ -221,10 +223,12 @@ void selector_to_path(state *st)
|
||||
st->rewrite[i].replace,
|
||||
st->req_selector + strlen(st->rewrite[i].match));
|
||||
|
||||
#ifdef HAVE_SYSLOG
|
||||
if (st->debug) {
|
||||
syslog(LOG_INFO, "rewriting selector \"%s\" -> \"%s\"",
|
||||
st->req_selector, buf);
|
||||
}
|
||||
#endif
|
||||
|
||||
sstrlcpy(st->req_selector, buf);
|
||||
}
|
||||
@ -530,7 +534,9 @@ int main(int argc, char *argv[])
|
||||
parse_args(&st, argc, argv);
|
||||
|
||||
/* Open syslog() */
|
||||
#ifdef HAVE_SYSLOG
|
||||
if (st.opt_syslog) openlog(self, LOG_PID, LOG_DAEMON);
|
||||
#endif
|
||||
|
||||
#ifdef __OpenBSD__
|
||||
/* unveil(2) support.
|
||||
@ -538,6 +544,9 @@ int main(int argc, char *argv[])
|
||||
* We only enable unveil(2) if the user isn't expecting to shell-out to
|
||||
* arbitrary commands.
|
||||
*/
|
||||
/*
|
||||
* We don't bother with HAVE_SYSLOG checks as OpenBSD has syslog.
|
||||
*/
|
||||
if (st.opt_exec) {
|
||||
if (st.extra_unveil_paths != NULL) {
|
||||
die(&st, NULL, "-U and executable maps cannot co-exist");
|
||||
@ -679,12 +688,16 @@ get_selector:
|
||||
/* Remove trailing CRLF */
|
||||
chomp(selector);
|
||||
|
||||
#ifdef HAVE_SYSLOG
|
||||
if (st.debug) syslog(LOG_INFO, "client sent us \"%s\"", selector);
|
||||
#endif
|
||||
|
||||
/* Handle HAproxy/Stunnel proxy protocol v1 */
|
||||
#ifdef ENABLE_HAPROXY1
|
||||
if (sstrncmp(selector, "PROXY TCP") == MATCH && st.opt_proxy) {
|
||||
#ifdef HAVE_SYSLOG
|
||||
if (st.debug) syslog(LOG_INFO, "got proxy protocol header \"%s\"", selector);
|
||||
#endif
|
||||
|
||||
sscanf(selector, "PROXY TCP%d %s %s %d %d",
|
||||
&dummy, remote, local, &dummy, &st.server_port);
|
||||
@ -715,7 +728,9 @@ get_selector:
|
||||
printf("+VIEWS:" CRLF " application/gopher+-menu: <512b>" CRLF);
|
||||
printf("." CRLF);
|
||||
|
||||
#ifdef HAVE_SYSLOG
|
||||
if (st.debug) syslog(LOG_INFO, "got a request for gopher+ root menu");
|
||||
#endif
|
||||
return OK;
|
||||
}
|
||||
|
||||
@ -727,8 +742,9 @@ get_selector:
|
||||
if ((c = strchr(selector, ' '))) *c = '\0';
|
||||
|
||||
st.req_protocol = PROTO_HTTP;
|
||||
|
||||
#ifdef HAVE_SYSLOG
|
||||
if (st.debug) syslog(LOG_INFO, "got HTTP request for \"%s\"", selector);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Save default server_host & fetch session data (including new server_host) */
|
||||
@ -798,7 +814,9 @@ get_selector:
|
||||
|
||||
/* Convert seletor to path & stat() */
|
||||
selector_to_path(&st);
|
||||
#ifdef HAVE_SYSLOG
|
||||
if (st.debug) syslog(LOG_INFO, "path to resource is \"%s\"", st.req_realpath);
|
||||
#endif
|
||||
|
||||
if (stat(st.req_realpath, &file) == ERROR) {
|
||||
|
||||
@ -856,6 +874,7 @@ get_selector:
|
||||
#endif
|
||||
|
||||
/* Log the request */
|
||||
#ifdef HAVE_SYSLOG
|
||||
if (st.opt_syslog) {
|
||||
syslog(LOG_INFO, "request for \"gopher%s://%s:%i/%c%s\" from %s",
|
||||
(st.server_port == st.server_tls_port ? "s" : ""),
|
||||
@ -865,6 +884,7 @@ get_selector:
|
||||
st.req_selector,
|
||||
st.req_remote_addr);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Check file type & act accordingly */
|
||||
switch (file.st_mode & S_IFMT) {
|
||||
|
@ -56,6 +56,7 @@
|
||||
#define HAVE_PASSWD /* For systems with passwd-like userdb */
|
||||
#define PASSWD_MIN_UID 100 /* Minimum allowed UID for ~userdirs */
|
||||
#define HAVE_LOCALES /* setlocale() and friends */
|
||||
#define HAVE_SYSLOG /* syslog() */
|
||||
#define HAVE_SHMEM /* Shared memory support */
|
||||
#define HAVE_UNAME /* uname() */
|
||||
#define HAVE_POPEN /* popen() */
|
||||
@ -99,6 +100,14 @@
|
||||
#define _LARGE_FILES 1
|
||||
#endif
|
||||
|
||||
/* Windows */
|
||||
#ifdef _WIN32
|
||||
#undef HAVE_SYSLOG
|
||||
#undef HAVE_SHMEM
|
||||
#undef HAVE_UNAME
|
||||
#undef HAVE_PASSWD
|
||||
#endif
|
||||
|
||||
/* Add other OS-specific defines here */
|
||||
|
||||
/*
|
||||
@ -113,9 +122,24 @@
|
||||
#include <string.h>
|
||||
#include <libgen.h>
|
||||
#include <time.h>
|
||||
|
||||
/* Windows */
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYSLOG
|
||||
#include <syslog.h>
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#ifndef _WIN32 // on windows we use windows.h
|
||||
#include <pwd.h>
|
||||
#endif
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#ifdef HAVE_SENDFILE
|
||||
@ -127,18 +151,20 @@
|
||||
#include <locale.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SHMEM
|
||||
#if defined(HAVE_SHMEM)
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
#else
|
||||
#define shm_state void
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_IPv4) || defined(HAVE_IPv6)
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UNAME
|
||||
#include <sys/utsname.h>
|
||||
@ -370,6 +396,11 @@ typedef struct {
|
||||
char opt_exec;
|
||||
char opt_personal_spaces;
|
||||
char debug;
|
||||
|
||||
/* Windows */
|
||||
#ifdef _WIN32
|
||||
WSADATA wsa_data;
|
||||
#endif
|
||||
} state;
|
||||
|
||||
/* Shared memory for session & accounting data */
|
||||
@ -408,8 +439,13 @@ typedef struct {
|
||||
typedef struct {
|
||||
char name[128]; /* Should be 256 but we're saving stack space */
|
||||
mode_t mode;
|
||||
#ifdef _WIN32
|
||||
int uid;
|
||||
int gid;
|
||||
#else
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
#endif
|
||||
off_t size;
|
||||
time_t mtime;
|
||||
} sdirent;
|
||||
|
2
menu.c
2
menu.c
@ -309,6 +309,7 @@ int gophermap(state *st, char *mapfile, int depth)
|
||||
}
|
||||
|
||||
/* Debug output */
|
||||
#ifdef HAVE_SYSLOG
|
||||
if (st->debug) {
|
||||
if (exe) {
|
||||
if (st->opt_exec)
|
||||
@ -318,6 +319,7 @@ int gophermap(state *st, char *mapfile, int depth)
|
||||
}
|
||||
else syslog(LOG_INFO, "parsing static gophermap \"%s\"", mapfile);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Try to execute or open the mapfile */
|
||||
if (exe & st->opt_exec) {
|
||||
|
@ -175,6 +175,10 @@ void parse_args(state *st, int argc, char *argv[])
|
||||
if (st->out_width < MIN_WIDTH) st->out_width = MIN_WIDTH;
|
||||
if (st->out_width < MIN_WIDTH + DATE_WIDTH) st->opt_date = FALSE;
|
||||
if (!st->opt_syslog) st->debug = FALSE;
|
||||
#ifdef _WIN32
|
||||
st->opt_syslog = FALSE;
|
||||
st->opt_shm = FALSE;
|
||||
#endif
|
||||
|
||||
/* Primary vhost directory must exist or we disable vhosting */
|
||||
if (st->opt_vhost) {
|
||||
|
Loading…
Reference in New Issue
Block a user