summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile57
-rw-r--r--catman.c16
-rw-r--r--cgi.c94
-rw-r--r--man.cgi.739
4 files changed, 96 insertions, 110 deletions
diff --git a/Makefile b/Makefile
index c4a8d67f..014cc8d1 100644
--- a/Makefile
+++ b/Makefile
@@ -27,7 +27,10 @@ CFLAGS += -DUSE_WCHAR
# system that's not OpenBSD or NetBSD. If uncommented, apropos(1),
# mandocdb(8), and man.cgi will popen(3) manpath(1) to get the MANPATH
# variable.
-# CFLAGS += -DUSE_MANPATH
+CFLAGS += -DUSE_MANPATH
+
+# If your system doesn't support static binaries, comment this.
+#STATIC = -static
CFLAGS += -g -DHAVE_CONFIG_H -DVERSION="\"$(VERSION)\""
CFLAGS += -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings
@@ -50,8 +53,8 @@ INSTALL_MAN = $(INSTALL_DATA)
# comment out apropos and mandocdb.
#
#DBLIB = -ldb
-DBBIN = apropos mandocdb man.cgi manup
-DBLN = llib-lapropos.ln llib-lmandocdb.ln llib-lman.cgi.ln llib-lmanup.ln
+DBBIN = apropos mandocdb man.cgi catman whatis
+DBLN = llib-lapropos.ln llib-lmandocdb.ln llib-lman.cgi.ln llib-lcatman.ln
all: mandoc preconv demandoc $(DBBIN)
@@ -108,8 +111,8 @@ SRCS = Makefile \
mandoc_char.7 \
manpath.c \
manpath.h \
- manup.c \
- manup.8 \
+ catman.c \
+ catman.8 \
mdoc.h \
mdoc.7 \
mdoc.c \
@@ -295,15 +298,30 @@ APROPOS_LNS = apropos.ln apropos_db.ln manpath.ln
$(APROPOS_OBJS) $(APROPOS_LNS): config.h mandoc.h apropos_db.h manpath.h mandocdb.h
-CGI_OBJS = cgi.o apropos_db.o manpath.o
-CGI_LNS = cgi.ln apropos_db.ln manpath.ln
+CGI_OBJS = $(MANDOC_HTML_OBJS) \
+ $(MANDOC_MAN_OBJS) \
+ $(MANDOC_TERM_OBJS) \
+ cgi.o \
+ apropos_db.o \
+ manpath.o \
+ out.o \
+ tree.o
-$(CGI_OBJS) $(CGI_LNS): config.h mandoc.h apropos_db.h manpath.h mandocdb.h
+CGI_LNS = $(MANDOC_HTML_LNS) \
+ $(MANDOC_MAN_LNS) \
+ $(MANDOC_TERM_LNS) \
+ cgi.ln \
+ apropos_db.ln \
+ manpath.ln \
+ out.ln \
+ tree.ln
-MANUP_OBJS = manup.o manpath.o
-MANUP_LNS = manup.ln manpath.ln
+$(CGI_OBJS) $(CGI_LNS): main.h mdoc.h man.h out.h config.h mandoc.h apropos_db.h manpath.h mandocdb.h
-$(MANUP_OBJS) $(MANUP_LNS): config.h mandoc.h manpath.h
+CATMAN_OBJS = catman.o manpath.o
+CATMAN_LNS = catman.ln manpath.ln
+
+$(CATMAN_OBJS) $(CATMAN_LNS): config.h mandoc.h manpath.h
DEMANDOC_OBJS = demandoc.o
DEMANDOC_LNS = demandoc.ln
@@ -395,8 +413,8 @@ clean:
rm -f llib-lapropos.ln $(APROPOS_LNS)
rm -f man.cgi $(CGI_OBJS)
rm -f llib-lman.cgi.ln $(CGI_LNS)
- rm -f manup $(MANUP_OBJS)
- rm -f llib-lmanup.ln $(MANUP_LNS)
+ rm -f catman $(CATMAN_OBJS)
+ rm -f llib-lcatman.ln $(CATMAN_LNS)
rm -f demandoc $(DEMANDOC_OBJS)
rm -f llib-ldemandoc.ln $(DEMANDOC_LNS)
rm -f mandoc $(MANDOC_OBJS)
@@ -462,20 +480,23 @@ preconv: $(PRECONV_OBJS)
llib-lpreconv.ln: $(PRECONV_LNS) llib-llibmandoc.ln
$(LINT) $(LINTFLAGS) -Cpreconv $(PRECONV_LNS) llib-llibmandoc.ln
+whatis: apropos
+ cp -f apropos whatis
+
apropos: $(APROPOS_OBJS) libmandoc.a
$(CC) $(LDFLAGS) -o $@ $(APROPOS_OBJS) libmandoc.a $(DBLIB)
llib-lapropos.ln: $(APROPOS_LNS) llib-llibmandoc.ln
$(LINT) $(LINTFLAGS) -Capropos $(APROPOS_LNS) llib-llibmandoc.ln
-manup: $(MANUP_OBJS) libmandoc.a
- $(CC) $(LDFLAGS) -o $@ $(MANUP_OBJS) libmandoc.a $(DBLIB)
+catman: $(CATMAN_OBJS) libmandoc.a
+ $(CC) $(LDFLAGS) -o $@ $(CATMAN_OBJS) libmandoc.a $(DBLIB)
-llib-lmanup.ln: $(MANUP_LNS) llib-llibmandoc.ln
- $(LINT) $(LINTFLAGS) -Cmanup $(MANUP_LNS) llib-llibmandoc.ln
+llib-lcatman.ln: $(CATMAN_LNS) llib-llibmandoc.ln
+ $(LINT) $(LINTFLAGS) -Ccatman $(CATMAN_LNS) llib-llibmandoc.ln
man.cgi: $(CGI_OBJS) libmandoc.a
- $(CC) $(LDFLAGS) -static -o $@ $(CGI_OBJS) libmandoc.a $(DBLIB)
+ $(CC) $(LDFLAGS) $(STATIC) -o $@ $(CGI_OBJS) libmandoc.a $(DBLIB)
llib-lman.cgi.ln: $(CGI_LNS) llib-llibmandoc.ln
$(LINT) $(LINTFLAGS) -Cman.cgi $(CGI_LNS) llib-llibmandoc.ln
diff --git a/catman.c b/catman.c
index fa3c2774..529d9055 100644
--- a/catman.c
+++ b/catman.c
@@ -52,8 +52,10 @@
} while (/* CONSTCOND */0)
static int indexhtml(char *);
+#if 0
static int jobstart(const char *, const char *, pid_t *);
static int jobwait(pid_t);
+#endif
static int manup(const struct manpaths *, const char *);
static int mkpath(char *, mode_t, mode_t);
static int treecpy(char *, char *);
@@ -194,6 +196,7 @@ out:
return(rc);
}
+#if 0
/*
* Clean up existing child.
* Return 1 if cleaned up fine (or none was started) and 0 otherwise.
@@ -252,6 +255,7 @@ jobstart(const char *dst, const char *src, pid_t *pid)
exit(EXIT_FAILURE);
/* NOTREACHED */
}
+#endif
/*
* Pass over the recno database and re-create HTML pages if they're
@@ -292,7 +296,7 @@ indexhtml(char *dst)
xstrlcat(dst, "/", MAXPATHLEN);
xstrlcat(dst, f, MAXPATHLEN);
- xstrlcat(dst, ".html", MAXPATHLEN);
+ /*xstrlcat(dst, ".html", MAXPATHLEN);*/
if (-1 == (rc = isnewer(dst, f))) {
fprintf(stderr, "%s: Manpage missing\n", f);
@@ -310,8 +314,12 @@ indexhtml(char *dst)
}
*d = '/';
- if ( ! jobstart(dst, f, &pid))
+
+ if ( ! filecpy(dst, f))
break;
+
+ /*if ( ! jobstart(dst, f, &pid))
+ break;*/
if (verbose)
printf("%s\n", dst);
}
@@ -320,8 +328,8 @@ indexhtml(char *dst)
if (c < 0)
perror(fname);
- if ( ! jobwait(pid))
- c = -1;
+ /*if ( ! jobwait(pid))
+ c = -1;*/
return(1 == c ? 1 : -1);
}
diff --git a/cgi.c b/cgi.c
index 4c82eb43..e395baf2 100644
--- a/cgi.c
+++ b/cgi.c
@@ -36,6 +36,9 @@
#include "apropos_db.h"
#include "mandoc.h"
+#include "mdoc.h"
+#include "man.h"
+#include "main.h"
#include "manpath.h"
#ifdef __linux__
@@ -63,8 +66,7 @@ struct req {
};
static int atou(const char *, unsigned *);
-static void format_insecure(const char *);
-static void format_secure(const char *);
+static void format(const char *);
static void html_print(const char *);
static int kval_decode(char *);
static void kval_parse(struct kval **, size_t *, char *);
@@ -86,7 +88,6 @@ static void resp_index(const struct req *);
static void resp_search(struct res *, size_t, void *);
static void resp_searchform(const struct req *);
-static int insecure = 1;
static const char *progname;
static const char *cache;
static const char *host;
@@ -434,56 +435,43 @@ pg_index(const struct manpaths *ps, const struct req *req, char *path)
}
static void
-format_insecure(const char *file)
+format(const char *file)
{
- pid_t pid;
- char cmd[MAXPATHLEN];
-
- strlcpy(cmd, "man=", MAXPATHLEN);
- strlcat(cmd, progname, MAXPATHLEN);
- strlcat(cmd, "/search?expr=%N&sec=%S", MAXPATHLEN);
-
- /* Get ready to call the child mandoc(1) process. */
-
- if (-1 == (pid = fork()))
- exit(EXIT_FAILURE);
+ struct mparse *mp;
+ int fd;
+ struct mdoc *mdoc;
+ struct man *man;
+ void *vp;
+ enum mandoclevel rc;
- if (pid > 0) {
- waitpid(pid, NULL, 0);
+ if (-1 == (fd = open(file, O_RDONLY, 0))) {
+ resp_baddb();
return;
}
- dup2(STDOUT_FILENO, STDERR_FILENO);
-
- puts("Content-Type: text/html; charset=utf-8\n");
-
- 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;
+ mp = mparse_alloc(MPARSE_AUTO, MANDOCLEVEL_FATAL, NULL, NULL);
+ rc = mparse_readfd(mp, fd, file);
+ close(fd);
- if (-1 == (fd = open(file, O_RDONLY, 0))) {
+ if (rc >= MANDOCLEVEL_FATAL) {
resp_baddb();
return;
}
- resp_begin_http(200, NULL);
+ mparse_result(mp, &mdoc, &man);
+ vp = html_alloc(NULL);
- do {
- ssz = read(fd, buf, BUFSIZ);
- if (ssz > 0)
- write(STDOUT_FILENO, buf, ssz);
- } while (ssz > 0);
+ if (NULL != mdoc) {
+ resp_begin_http(200, NULL);
+ html_mdoc(vp, mdoc);
+ } else if (NULL != man) {
+ resp_begin_http(200, NULL);
+ html_man(vp, man);
+ } else
+ resp_baddb();
- close(fd);
+ html_free(vp);
+ mparse_free(mp);
}
static void
@@ -535,17 +523,13 @@ pg_show(const struct manpaths *ps, const struct req *req, char *path)
/* Extra filename: the first nil-terminated entry. */
- (*db->close)(db);
-
strlcpy(file, ps->paths[vol], MAXPATHLEN);
strlcat(file, "/", MAXPATHLEN);
strlcat(file, (char *)val.data, MAXPATHLEN);
- if ( ! insecure) {
- strlcat(file, ".html", MAXPATHLEN);
- format_secure(file);
- } else
- format_insecure(file);
+ (*db->close)(db);
+
+ format(file);
}
static void
@@ -638,12 +622,9 @@ main(void)
if (NULL == cache)
cache = "/cache/man.cgi";
- if (NULL == getenv("INSECURE")) {
- insecure = 0;
- if (-1 == chdir(cache)) {
- resp_bad();
- return(EXIT_FAILURE);
- }
+ if (-1 == chdir(cache)) {
+ resp_bad();
+ return(EXIT_FAILURE);
}
host = getenv("HTTP_HOST");
@@ -689,10 +670,7 @@ main(void)
/* Initialise MANPATH. */
memset(&paths, 0, sizeof(struct manpaths));
- if ( ! insecure)
- manpath_manconf("etc/man.conf", &paths);
- else
- manpath_parse(&paths, NULL, NULL);
+ manpath_manconf("etc/man.conf", &paths);
/* Route pages. */
diff --git a/man.cgi.7 b/man.cgi.7
index 1a865e76..67be8101 100644
--- a/man.cgi.7
+++ b/man.cgi.7
@@ -15,31 +15,13 @@ It interfaces with
databases for query and with
.Xr mandoc 1
for display.
-This script operates in two modes: secure and insecure.
-.Bl -tag -width Ds
-.It insecure
-Act as a web-based
-.Xr apropos 1
-and
-.Xr mandoc 1 .
-This assumes full access to the file-system.
-It is not recommended for public-facing servers.
-.It secure
-Act on manual pages cached by
-.Xr manup 8 .
-A cached file tree is queried for pre-formatted manuals.
-.El
-.Pp
-To run in insecure mode, drop
-.Nm
-into your web-server's CGI directory.
-The environment variable
-.Ev INSECURE
-must be set.
+It operates over a cache of manuals generated by
+.Xr catman 8 .
.Pp
-To run in secure mode, you must maintain a cache directory of
-preformatted manuals using
-.Xr manup 8 .
+To use
+.Nm ,
+first create a manual cache in
+.Xr catman 8 .
If your web-server is running in a jail, the cache directory must be
within the jail.
Set the environment variable
@@ -51,12 +33,9 @@ If you're running in a jailed web-server, make sure the
directory exists and is writable.
.Sh ENVIRONMENT
.Bl -tag -width Ds
-.It Er INSECURE
-Run in insecure mode.
-Not recommended.
.It Er CACHE_DIR
The absolute path of the
-.Xr manup 8
+.Xr catman 8
cache directory.
.El
.Sh FILES
@@ -64,11 +43,11 @@ The configuration file
.Pa etc/man.conf
must exist within the cache directory.
This is built by
-.Xr manup 8 .
+.Xr catman 8 .
.Sh SEE ALSO
.Xr apropos 1 ,
.Xr mandoc 1 ,
-.Xr manup 8 ,
+.Xr catman 8 ,
.Xr mandocdb 8
.Sh AUTHORS
The