version 1.7, 2011/11/24 12:27:18 |
version 1.8, 2011/11/27 11:46:44 |
|
|
|
|
#include "apropos_db.h" |
#include "apropos_db.h" |
#include "mandoc.h" |
#include "mandoc.h" |
|
#include "mdoc.h" |
|
#include "man.h" |
|
#include "main.h" |
#include "manpath.h" |
#include "manpath.h" |
|
|
#ifdef __linux__ |
#ifdef __linux__ |
|
|
}; |
}; |
|
|
static int atou(const char *, unsigned *); |
static int atou(const char *, unsigned *); |
static void format_insecure(const char *); |
static void format(const char *); |
static void format_secure(const char *); |
|
static void html_print(const char *); |
static void html_print(const char *); |
static int kval_decode(char *); |
static int kval_decode(char *); |
static void kval_parse(struct kval **, size_t *, char *); |
static void kval_parse(struct kval **, size_t *, char *); |
Line 86 static void resp_index(const struct req *); |
|
Line 88 static void resp_index(const struct req *); |
|
static void resp_search(struct res *, size_t, void *); |
static void resp_search(struct res *, size_t, void *); |
static void resp_searchform(const struct req *); |
static void resp_searchform(const struct req *); |
|
|
static int insecure = 1; |
|
static const char *progname; |
static const char *progname; |
static const char *cache; |
static const char *cache; |
static const char *host; |
static const char *host; |
Line 434 pg_index(const struct manpaths *ps, const struct req * |
|
Line 435 pg_index(const struct manpaths *ps, const struct req * |
|
} |
} |
|
|
static void |
static void |
format_insecure(const char *file) |
format(const char *file) |
{ |
{ |
pid_t pid; |
struct mparse *mp; |
char cmd[MAXPATHLEN]; |
int fd; |
|
struct mdoc *mdoc; |
|
struct man *man; |
|
void *vp; |
|
enum mandoclevel rc; |
|
|
strlcpy(cmd, "man=", MAXPATHLEN); |
if (-1 == (fd = open(file, O_RDONLY, 0))) { |
strlcat(cmd, progname, MAXPATHLEN); |
resp_baddb(); |
strlcat(cmd, "/search?expr=%N&sec=%S", MAXPATHLEN); |
|
|
|
/* Get ready to call the child mandoc(1) process. */ |
|
|
|
if (-1 == (pid = fork())) |
|
exit(EXIT_FAILURE); |
|
|
|
if (pid > 0) { |
|
waitpid(pid, NULL, 0); |
|
return; |
return; |
} |
} |
|
|
dup2(STDOUT_FILENO, STDERR_FILENO); |
mp = mparse_alloc(MPARSE_AUTO, MANDOCLEVEL_FATAL, NULL, NULL); |
|
rc = mparse_readfd(mp, fd, file); |
|
close(fd); |
|
|
puts("Content-Type: text/html; charset=utf-8\n"); |
if (rc >= MANDOCLEVEL_FATAL) { |
|
|
fflush(stdout); |
|
|
|
execlp("mandoc", "mandoc", "-T", |
|
"html", "-O", cmd, file, (char *)NULL); |
|
} |
|
|
|
static void |
|
format_secure(const char *file) |
|
{ |
|
char buf[BUFSIZ]; |
|
int fd; |
|
ssize_t ssz; |
|
|
|
if (-1 == (fd = open(file, O_RDONLY, 0))) { |
|
resp_baddb(); |
resp_baddb(); |
return; |
return; |
} |
} |
|
|
resp_begin_http(200, NULL); |
mparse_result(mp, &mdoc, &man); |
|
vp = html_alloc(NULL); |
|
|
do { |
if (NULL != mdoc) { |
ssz = read(fd, buf, BUFSIZ); |
resp_begin_http(200, NULL); |
if (ssz > 0) |
html_mdoc(vp, mdoc); |
write(STDOUT_FILENO, buf, ssz); |
} else if (NULL != man) { |
} while (ssz > 0); |
resp_begin_http(200, NULL); |
|
html_man(vp, man); |
|
} else |
|
resp_baddb(); |
|
|
close(fd); |
html_free(vp); |
|
mparse_free(mp); |
} |
} |
|
|
static void |
static void |
Line 535 pg_show(const struct manpaths *ps, const struct req *r |
|
Line 523 pg_show(const struct manpaths *ps, const struct req *r |
|
|
|
/* Extra filename: the first nil-terminated entry. */ |
/* Extra filename: the first nil-terminated entry. */ |
|
|
(*db->close)(db); |
|
|
|
strlcpy(file, ps->paths[vol], MAXPATHLEN); |
strlcpy(file, ps->paths[vol], MAXPATHLEN); |
strlcat(file, "/", MAXPATHLEN); |
strlcat(file, "/", MAXPATHLEN); |
strlcat(file, (char *)val.data, MAXPATHLEN); |
strlcat(file, (char *)val.data, MAXPATHLEN); |
|
|
if ( ! insecure) { |
(*db->close)(db); |
strlcat(file, ".html", MAXPATHLEN); |
|
format_secure(file); |
format(file); |
} else |
|
format_insecure(file); |
|
} |
} |
|
|
static void |
static void |
|
|
if (NULL == cache) |
if (NULL == cache) |
cache = "/cache/man.cgi"; |
cache = "/cache/man.cgi"; |
|
|
if (NULL == getenv("INSECURE")) { |
if (-1 == chdir(cache)) { |
insecure = 0; |
resp_bad(); |
if (-1 == chdir(cache)) { |
return(EXIT_FAILURE); |
resp_bad(); |
|
return(EXIT_FAILURE); |
|
} |
|
} |
} |
|
|
host = getenv("HTTP_HOST"); |
host = getenv("HTTP_HOST"); |
|
|
/* Initialise MANPATH. */ |
/* Initialise MANPATH. */ |
|
|
memset(&paths, 0, sizeof(struct manpaths)); |
memset(&paths, 0, sizeof(struct manpaths)); |
if ( ! insecure) |
manpath_manconf("etc/man.conf", &paths); |
manpath_manconf("etc/man.conf", &paths); |
|
else |
|
manpath_parse(&paths, NULL, NULL); |
|
|
|
/* Route pages. */ |
/* Route pages. */ |
|
|