Annotation of src/usr.bin/mandoc/cgi.c, Revision 1.97
1.97 ! schwarze 1: /* $OpenBSD: cgi.c,v 1.96 2018/05/29 20:32:41 schwarze Exp $ */
1.1 schwarze 2: /*
3: * Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
1.81 schwarze 4: * Copyright (c) 2014, 2015, 2016, 2017 Ingo Schwarze <schwarze@usta.de>
1.1 schwarze 5: *
6: * Permission to use, copy, modify, and distribute this software for any
7: * purpose with or without fee is hereby granted, provided that the above
8: * copyright notice and this permission notice appear in all copies.
9: *
1.44 schwarze 10: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
1.1 schwarze 11: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1.44 schwarze 12: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
1.1 schwarze 13: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17: */
1.33 schwarze 18: #include <sys/types.h>
19: #include <sys/time.h>
20:
1.1 schwarze 21: #include <ctype.h>
1.67 schwarze 22: #include <err.h>
1.1 schwarze 23: #include <errno.h>
24: #include <fcntl.h>
25: #include <limits.h>
1.32 schwarze 26: #include <stdint.h>
1.1 schwarze 27: #include <stdio.h>
28: #include <stdlib.h>
29: #include <string.h>
30: #include <unistd.h>
31:
1.47 schwarze 32: #include "mandoc_aux.h"
1.1 schwarze 33: #include "mandoc.h"
1.47 schwarze 34: #include "roff.h"
1.50 schwarze 35: #include "mdoc.h"
1.51 schwarze 36: #include "man.h"
1.1 schwarze 37: #include "main.h"
1.44 schwarze 38: #include "manconf.h"
1.1 schwarze 39: #include "mansearch.h"
1.7 schwarze 40: #include "cgi.h"
1.1 schwarze 41:
42: /*
43: * A query as passed to the search function.
44: */
45: struct query {
1.23 schwarze 46: char *manpath; /* desired manual directory */
47: char *arch; /* architecture */
48: char *sec; /* manual section */
1.25 schwarze 49: char *query; /* unparsed query expression */
1.5 schwarze 50: int equal; /* match whole names, not substrings */
1.1 schwarze 51: };
52:
53: struct req {
54: struct query q;
55: char **p; /* array of available manpaths */
56: size_t psz; /* number of available manpaths */
1.60 schwarze 57: int isquery; /* QUERY_STRING used, not PATH_INFO */
1.1 schwarze 58: };
59:
1.70 schwarze 60: enum focus {
61: FOCUS_NONE = 0,
62: FOCUS_QUERY
63: };
64:
1.1 schwarze 65: static void html_print(const char *);
66: static void html_putchar(char);
1.43 schwarze 67: static int http_decode(char *);
1.97 ! schwarze 68: static void http_encode(const char *p);
1.68 schwarze 69: static void parse_manpath_conf(struct req *);
70: static void parse_path_info(struct req *req, const char *path);
71: static void parse_query_string(struct req *, const char *);
1.12 schwarze 72: static void pg_error_badrequest(const char *);
73: static void pg_error_internal(void);
74: static void pg_index(const struct req *);
75: static void pg_noresult(const struct req *, const char *);
1.87 schwarze 76: static void pg_redirect(const struct req *, const char *);
1.6 schwarze 77: static void pg_search(const struct req *);
1.12 schwarze 78: static void pg_searchres(const struct req *,
79: struct manpage *, size_t);
1.19 schwarze 80: static void pg_show(struct req *, const char *);
1.88 schwarze 81: static void resp_begin_html(int, const char *, const char *);
1.1 schwarze 82: static void resp_begin_http(int, const char *);
1.68 schwarze 83: static void resp_catman(const struct req *, const char *);
1.53 schwarze 84: static void resp_copy(const char *);
1.1 schwarze 85: static void resp_end_html(void);
1.68 schwarze 86: static void resp_format(const struct req *, const char *);
1.70 schwarze 87: static void resp_searchform(const struct req *, enum focus);
1.10 schwarze 88: static void resp_show(const struct req *, const char *);
1.25 schwarze 89: static void set_query_attr(char **, char **);
1.97 ! schwarze 90: static int validate_arch(const char *);
1.25 schwarze 91: static int validate_filename(const char *);
92: static int validate_manpath(const struct req *, const char *);
93: static int validate_urifrag(const char *);
1.1 schwarze 94:
1.58 schwarze 95: static const char *scriptname = SCRIPT_NAME;
1.1 schwarze 96:
1.10 schwarze 97: static const int sec_prios[] = {1, 4, 5, 8, 6, 3, 7, 2, 9};
1.8 schwarze 98: static const char *const sec_numbers[] = {
99: "0", "1", "2", "3", "3p", "4", "5", "6", "7", "8", "9"
100: };
101: static const char *const sec_names[] = {
102: "All Sections",
103: "1 - General Commands",
104: "2 - System Calls",
1.34 schwarze 105: "3 - Library Functions",
106: "3p - Perl Library",
107: "4 - Device Drivers",
1.8 schwarze 108: "5 - File Formats",
109: "6 - Games",
1.34 schwarze 110: "7 - Miscellaneous Information",
111: "8 - System Manager\'s Manual",
112: "9 - Kernel Developer\'s Manual"
1.8 schwarze 113: };
114: static const int sec_MAX = sizeof(sec_names) / sizeof(char *);
115:
116: static const char *const arch_names[] = {
1.85 deraadt 117: "amd64", "alpha", "armv7", "arm64",
1.76 schwarze 118: "hppa", "i386", "landisk",
1.64 schwarze 119: "loongson", "luna88k", "macppc", "mips64",
1.79 schwarze 120: "octeon", "sgi", "socppc", "sparc64",
1.76 schwarze 121: "amiga", "arc", "armish", "arm32",
122: "atari", "aviion", "beagle", "cats",
123: "hppa64", "hp300",
1.64 schwarze 124: "ia64", "mac68k", "mvme68k", "mvme88k",
125: "mvmeppc", "palm", "pc532", "pegasos",
1.78 schwarze 126: "pmax", "powerpc", "solbourne", "sparc",
1.79 schwarze 127: "sun3", "vax", "wgrisc", "x68k",
128: "zaurus"
1.8 schwarze 129: };
130: static const int arch_MAX = sizeof(arch_names) / sizeof(char *);
131:
1.1 schwarze 132: /*
133: * Print a character, escaping HTML along the way.
134: * This will pass non-ASCII straight to output: be warned!
135: */
136: static void
137: html_putchar(char c)
138: {
139:
140: switch (c) {
1.93 schwarze 141: case '"':
1.80 bentley 142: printf(""");
1.1 schwarze 143: break;
1.93 schwarze 144: case '&':
1.1 schwarze 145: printf("&");
146: break;
1.93 schwarze 147: case '>':
1.1 schwarze 148: printf(">");
149: break;
1.93 schwarze 150: case '<':
1.1 schwarze 151: printf("<");
152: break;
153: default:
154: putchar((unsigned char)c);
155: break;
156: }
157: }
158:
159: /*
160: * Call through to html_putchar().
161: * Accepts NULL strings.
162: */
163: static void
164: html_print(const char *p)
165: {
1.43 schwarze 166:
1.1 schwarze 167: if (NULL == p)
168: return;
169: while ('\0' != *p)
170: html_putchar(*p++);
171: }
172:
173: /*
1.23 schwarze 174: * Transfer the responsibility for the allocated string *val
175: * to the query structure.
1.1 schwarze 176: */
177: static void
1.23 schwarze 178: set_query_attr(char **attr, char **val)
1.1 schwarze 179: {
180:
1.23 schwarze 181: free(*attr);
182: if (**val == '\0') {
183: *attr = NULL;
184: free(*val);
185: } else
186: *attr = *val;
187: *val = NULL;
188: }
189:
190: /*
191: * Parse the QUERY_STRING for key-value pairs
192: * and store the values into the query structure.
193: */
194: static void
1.68 schwarze 195: parse_query_string(struct req *req, const char *qs)
1.23 schwarze 196: {
197: char *key, *val;
198: size_t keysz, valsz;
199:
1.60 schwarze 200: req->isquery = 1;
1.23 schwarze 201: req->q.manpath = NULL;
202: req->q.arch = NULL;
203: req->q.sec = NULL;
1.25 schwarze 204: req->q.query = NULL;
1.23 schwarze 205: req->q.equal = 1;
206:
207: key = val = NULL;
208: while (*qs != '\0') {
1.1 schwarze 209:
1.23 schwarze 210: /* Parse one key. */
211:
212: keysz = strcspn(qs, "=;&");
213: key = mandoc_strndup(qs, keysz);
214: qs += keysz;
215: if (*qs != '=')
216: goto next;
217:
218: /* Parse one value. */
219:
220: valsz = strcspn(++qs, ";&");
221: val = mandoc_strndup(qs, valsz);
222: qs += valsz;
223:
224: /* Decode and catch encoding errors. */
1.1 schwarze 225:
1.23 schwarze 226: if ( ! (http_decode(key) && http_decode(val)))
227: goto next;
1.1 schwarze 228:
1.23 schwarze 229: /* Handle key-value pairs. */
1.1 schwarze 230:
1.23 schwarze 231: if ( ! strcmp(key, "query"))
1.25 schwarze 232: set_query_attr(&req->q.query, &val);
1.1 schwarze 233:
1.23 schwarze 234: else if ( ! strcmp(key, "apropos"))
235: req->q.equal = !strcmp(val, "0");
236:
237: else if ( ! strcmp(key, "manpath")) {
1.13 schwarze 238: #ifdef COMPAT_OLDURI
1.23 schwarze 239: if ( ! strncmp(val, "OpenBSD ", 8)) {
1.13 schwarze 240: val[7] = '-';
241: if ('C' == val[8])
242: val[8] = 'c';
243: }
244: #endif
1.23 schwarze 245: set_query_attr(&req->q.manpath, &val);
246: }
247:
248: else if ( ! (strcmp(key, "sec")
1.13 schwarze 249: #ifdef COMPAT_OLDURI
1.23 schwarze 250: && strcmp(key, "sektion")
1.13 schwarze 251: #endif
1.23 schwarze 252: )) {
253: if ( ! strcmp(val, "0"))
254: *val = '\0';
255: set_query_attr(&req->q.sec, &val);
1.5 schwarze 256: }
1.23 schwarze 257:
258: else if ( ! strcmp(key, "arch")) {
259: if ( ! strcmp(val, "default"))
260: *val = '\0';
261: set_query_attr(&req->q.arch, &val);
262: }
263:
264: /*
265: * The key must be freed in any case.
266: * The val may have been handed over to the query
267: * structure, in which case it is now NULL.
268: */
269: next:
270: free(key);
271: key = NULL;
272: free(val);
273: val = NULL;
274:
275: if (*qs != '\0')
276: qs++;
1.1 schwarze 277: }
278: }
279:
280: /*
281: * HTTP-decode a string. The standard explanation is that this turns
282: * "%4e+foo" into "n foo" in the regular way. This is done in-place
283: * over the allocated string.
284: */
285: static int
286: http_decode(char *p)
287: {
288: char hex[3];
1.3 tedu 289: char *q;
1.1 schwarze 290: int c;
291:
292: hex[2] = '\0';
293:
1.3 tedu 294: q = p;
295: for ( ; '\0' != *p; p++, q++) {
1.1 schwarze 296: if ('%' == *p) {
297: if ('\0' == (hex[0] = *(p + 1)))
1.48 schwarze 298: return 0;
1.1 schwarze 299: if ('\0' == (hex[1] = *(p + 2)))
1.48 schwarze 300: return 0;
1.1 schwarze 301: if (1 != sscanf(hex, "%x", &c))
1.48 schwarze 302: return 0;
1.1 schwarze 303: if ('\0' == c)
1.48 schwarze 304: return 0;
1.1 schwarze 305:
1.3 tedu 306: *q = (char)c;
307: p += 2;
1.1 schwarze 308: } else
1.3 tedu 309: *q = '+' == *p ? ' ' : *p;
1.1 schwarze 310: }
311:
1.3 tedu 312: *q = '\0';
1.48 schwarze 313: return 1;
1.1 schwarze 314: }
315:
316: static void
1.97 ! schwarze 317: http_encode(const char *p)
! 318: {
! 319: for (; *p != '\0'; p++) {
! 320: if (isalnum((unsigned char)*p) == 0 &&
! 321: strchr("-._~", *p) == NULL)
! 322: printf("%%%02.2X", (unsigned char)*p);
! 323: else
! 324: putchar(*p);
! 325: }
! 326: }
! 327:
! 328: static void
1.1 schwarze 329: resp_begin_http(int code, const char *msg)
330: {
331:
332: if (200 != code)
1.2 tedu 333: printf("Status: %d %s\r\n", code, msg);
1.1 schwarze 334:
1.2 tedu 335: printf("Content-Type: text/html; charset=utf-8\r\n"
336: "Cache-Control: no-cache\r\n"
337: "Pragma: no-cache\r\n"
338: "\r\n");
1.1 schwarze 339:
340: fflush(stdout);
341: }
342:
343: static void
1.53 schwarze 344: resp_copy(const char *filename)
345: {
346: char buf[4096];
347: ssize_t sz;
348: int fd;
349:
350: if ((fd = open(filename, O_RDONLY)) != -1) {
351: fflush(stdout);
352: while ((sz = read(fd, buf, sizeof(buf))) > 0)
353: write(STDOUT_FILENO, buf, sz);
1.77 jsg 354: close(fd);
1.53 schwarze 355: }
356: }
357:
358: static void
1.88 schwarze 359: resp_begin_html(int code, const char *msg, const char *file)
1.1 schwarze 360: {
1.88 schwarze 361: char *cp;
1.1 schwarze 362:
363: resp_begin_http(code, msg);
364:
1.37 schwarze 365: printf("<!DOCTYPE html>\n"
1.65 schwarze 366: "<html>\n"
367: "<head>\n"
1.82 schwarze 368: " <meta charset=\"UTF-8\"/>\n"
1.95 schwarze 369: " <meta name=\"viewport\""
370: " content=\"width=device-width, initial-scale=1.0\">\n"
1.82 schwarze 371: " <link rel=\"stylesheet\" href=\"%s/mandoc.css\""
1.65 schwarze 372: " type=\"text/css\" media=\"all\">\n"
1.88 schwarze 373: " <title>",
374: CSS_DIR);
375: if (file != NULL) {
376: if ((cp = strrchr(file, '/')) != NULL)
377: file = cp + 1;
378: if ((cp = strrchr(file, '.')) != NULL) {
379: printf("%.*s(%s) - ", (int)(cp - file), file, cp + 1);
380: } else
381: printf("%s - ", file);
382: }
383: printf("%s</title>\n"
1.65 schwarze 384: "</head>\n"
1.81 schwarze 385: "<body>\n",
1.88 schwarze 386: CUSTOMIZE_TITLE);
1.53 schwarze 387:
388: resp_copy(MAN_DIR "/header.html");
1.1 schwarze 389: }
390:
391: static void
392: resp_end_html(void)
393: {
394:
1.53 schwarze 395: resp_copy(MAN_DIR "/footer.html");
396:
1.65 schwarze 397: puts("</body>\n"
398: "</html>");
1.1 schwarze 399: }
400:
401: static void
1.70 schwarze 402: resp_searchform(const struct req *req, enum focus focus)
1.1 schwarze 403: {
404: int i;
405:
1.81 schwarze 406: printf("<form action=\"/%s\" method=\"get\">\n"
1.82 schwarze 407: " <fieldset>\n"
408: " <legend>Manual Page Search Parameters</legend>\n",
1.1 schwarze 409: scriptname);
1.8 schwarze 410:
411: /* Write query input box. */
412:
1.96 schwarze 413: printf(" <input type=\"search\" name=\"query\" value=\"");
1.70 schwarze 414: if (req->q.query != NULL)
1.25 schwarze 415: html_print(req->q.query);
1.70 schwarze 416: printf( "\" size=\"40\"");
417: if (focus == FOCUS_QUERY)
418: printf(" autofocus");
419: puts(">");
1.8 schwarze 420:
1.71 schwarze 421: /* Write submission buttons. */
1.8 schwarze 422:
1.82 schwarze 423: printf( " <button type=\"submit\" name=\"apropos\" value=\"0\">"
1.71 schwarze 424: "man</button>\n"
1.82 schwarze 425: " <button type=\"submit\" name=\"apropos\" value=\"1\">"
426: "apropos</button>\n"
427: " <br/>\n");
1.8 schwarze 428:
429: /* Write section selector. */
430:
1.82 schwarze 431: puts(" <select name=\"sec\">");
1.8 schwarze 432: for (i = 0; i < sec_MAX; i++) {
1.82 schwarze 433: printf(" <option value=\"%s\"", sec_numbers[i]);
1.8 schwarze 434: if (NULL != req->q.sec &&
435: 0 == strcmp(sec_numbers[i], req->q.sec))
1.65 schwarze 436: printf(" selected=\"selected\"");
437: printf(">%s</option>\n", sec_names[i]);
1.8 schwarze 438: }
1.82 schwarze 439: puts(" </select>");
1.8 schwarze 440:
441: /* Write architecture selector. */
442:
1.82 schwarze 443: printf( " <select name=\"arch\">\n"
444: " <option value=\"default\"");
1.21 schwarze 445: if (NULL == req->q.arch)
1.65 schwarze 446: printf(" selected=\"selected\"");
447: puts(">All Architectures</option>");
1.8 schwarze 448: for (i = 0; i < arch_MAX; i++) {
1.96 schwarze 449: printf(" <option");
1.8 schwarze 450: if (NULL != req->q.arch &&
451: 0 == strcmp(arch_names[i], req->q.arch))
1.65 schwarze 452: printf(" selected=\"selected\"");
453: printf(">%s</option>\n", arch_names[i]);
1.8 schwarze 454: }
1.82 schwarze 455: puts(" </select>");
1.8 schwarze 456:
457: /* Write manpath selector. */
458:
1.1 schwarze 459: if (req->psz > 1) {
1.82 schwarze 460: puts(" <select name=\"manpath\">");
1.1 schwarze 461: for (i = 0; i < (int)req->psz; i++) {
1.96 schwarze 462: printf(" <option");
1.41 schwarze 463: if (strcmp(req->q.manpath, req->p[i]) == 0)
1.96 schwarze 464: printf(" selected=\"selected\"");
465: printf(">");
1.1 schwarze 466: html_print(req->p[i]);
1.65 schwarze 467: puts("</option>");
1.1 schwarze 468: }
1.82 schwarze 469: puts(" </select>");
1.1 schwarze 470: }
1.8 schwarze 471:
1.82 schwarze 472: puts(" </fieldset>\n"
1.81 schwarze 473: "</form>");
1.1 schwarze 474: }
475:
1.16 schwarze 476: static int
1.20 schwarze 477: validate_urifrag(const char *frag)
478: {
479:
480: while ('\0' != *frag) {
481: if ( ! (isalnum((unsigned char)*frag) ||
482: '-' == *frag || '.' == *frag ||
483: '/' == *frag || '_' == *frag))
1.48 schwarze 484: return 0;
1.20 schwarze 485: frag++;
486: }
1.48 schwarze 487: return 1;
1.20 schwarze 488: }
489:
490: static int
1.17 schwarze 491: validate_manpath(const struct req *req, const char* manpath)
492: {
493: size_t i;
494:
495: for (i = 0; i < req->psz; i++)
496: if ( ! strcmp(manpath, req->p[i]))
1.48 schwarze 497: return 1;
1.17 schwarze 498:
1.48 schwarze 499: return 0;
1.17 schwarze 500: }
501:
502: static int
1.97 ! schwarze 503: validate_arch(const char *arch)
! 504: {
! 505: int i;
! 506:
! 507: for (i = 0; i < arch_MAX; i++)
! 508: if (strcmp(arch, arch_names[i]) == 0)
! 509: return 1;
! 510:
! 511: return 0;
! 512: }
! 513:
! 514: static int
1.16 schwarze 515: validate_filename(const char *file)
516: {
517:
518: if ('.' == file[0] && '/' == file[1])
519: file += 2;
520:
1.48 schwarze 521: return ! (strstr(file, "../") || strstr(file, "/..") ||
522: (strncmp(file, "man", 3) && strncmp(file, "cat", 3)));
1.16 schwarze 523: }
524:
1.1 schwarze 525: static void
1.12 schwarze 526: pg_index(const struct req *req)
1.1 schwarze 527: {
528:
1.88 schwarze 529: resp_begin_html(200, NULL, NULL);
1.70 schwarze 530: resp_searchform(req, FOCUS_QUERY);
1.65 schwarze 531: printf("<p>\n"
1.26 schwarze 532: "This web interface is documented in the\n"
1.83 schwarze 533: "<a class=\"Xr\" href=\"/%s%sman.cgi.8\">man.cgi(8)</a>\n"
1.26 schwarze 534: "manual, and the\n"
1.83 schwarze 535: "<a class=\"Xr\" href=\"/%s%sapropos.1\">apropos(1)</a>\n"
1.9 schwarze 536: "manual explains the query syntax.\n"
1.65 schwarze 537: "</p>\n",
1.58 schwarze 538: scriptname, *scriptname == '\0' ? "" : "/",
539: scriptname, *scriptname == '\0' ? "" : "/");
1.1 schwarze 540: resp_end_html();
541: }
542:
543: static void
1.12 schwarze 544: pg_noresult(const struct req *req, const char *msg)
1.1 schwarze 545: {
1.88 schwarze 546: resp_begin_html(200, NULL, NULL);
1.70 schwarze 547: resp_searchform(req, FOCUS_QUERY);
1.65 schwarze 548: puts("<p>");
1.1 schwarze 549: puts(msg);
1.65 schwarze 550: puts("</p>");
1.1 schwarze 551: resp_end_html();
552: }
553:
554: static void
1.12 schwarze 555: pg_error_badrequest(const char *msg)
1.1 schwarze 556: {
557:
1.88 schwarze 558: resp_begin_html(400, "Bad Request", NULL);
1.65 schwarze 559: puts("<h1>Bad Request</h1>\n"
560: "<p>\n");
1.1 schwarze 561: puts(msg);
562: printf("Try again from the\n"
1.65 schwarze 563: "<a href=\"/%s\">main page</a>.\n"
564: "</p>", scriptname);
1.1 schwarze 565: resp_end_html();
566: }
567:
568: static void
1.12 schwarze 569: pg_error_internal(void)
1.1 schwarze 570: {
1.88 schwarze 571: resp_begin_html(500, "Internal Server Error", NULL);
1.65 schwarze 572: puts("<p>Internal Server Error</p>");
1.1 schwarze 573: resp_end_html();
574: }
575:
576: static void
1.87 schwarze 577: pg_redirect(const struct req *req, const char *name)
578: {
1.91 schwarze 579: printf("Status: 303 See Other\r\n"
580: "Location: /");
1.87 schwarze 581: if (*scriptname != '\0')
582: printf("%s/", scriptname);
583: if (strcmp(req->q.manpath, req->p[0]))
584: printf("%s/", req->q.manpath);
585: if (req->q.arch != NULL)
586: printf("%s/", req->q.arch);
1.97 ! schwarze 587: http_encode(name);
! 588: if (req->q.sec != NULL) {
! 589: putchar('.');
! 590: http_encode(req->q.sec);
! 591: }
1.87 schwarze 592: printf("\r\nContent-Type: text/html; charset=utf-8\r\n\r\n");
593: }
594:
595: static void
1.12 schwarze 596: pg_searchres(const struct req *req, struct manpage *r, size_t sz)
1.1 schwarze 597: {
1.21 schwarze 598: char *arch, *archend;
1.59 schwarze 599: const char *sec;
600: size_t i, iuse;
1.21 schwarze 601: int archprio, archpriouse;
1.10 schwarze 602: int prio, priouse;
1.1 schwarze 603:
1.16 schwarze 604: for (i = 0; i < sz; i++) {
605: if (validate_filename(r[i].file))
606: continue;
1.67 schwarze 607: warnx("invalid filename %s in %s database",
1.16 schwarze 608: r[i].file, req->q.manpath);
609: pg_error_internal();
610: return;
611: }
612:
1.60 schwarze 613: if (req->isquery && sz == 1) {
1.1 schwarze 614: /*
615: * If we have just one result, then jump there now
616: * without any delay.
617: */
1.91 schwarze 618: printf("Status: 303 See Other\r\n"
619: "Location: /");
620: if (*scriptname != '\0')
621: printf("%s/", scriptname);
622: if (strcmp(req->q.manpath, req->p[0]))
623: printf("%s/", req->q.manpath);
624: printf("%s\r\n"
625: "Content-Type: text/html; charset=utf-8\r\n\r\n",
626: r[0].file);
1.1 schwarze 627: return;
628: }
629:
1.10 schwarze 630: /*
631: * In man(1) mode, show one of the pages
632: * even if more than one is found.
633: */
634:
1.88 schwarze 635: iuse = 0;
1.62 schwarze 636: if (req->q.equal || sz == 1) {
1.59 schwarze 637: priouse = 20;
1.21 schwarze 638: archpriouse = 3;
1.10 schwarze 639: for (i = 0; i < sz; i++) {
1.59 schwarze 640: sec = r[i].file;
641: sec += strcspn(sec, "123456789");
642: if (sec[0] == '\0')
1.10 schwarze 643: continue;
1.59 schwarze 644: prio = sec_prios[sec[0] - '1'];
645: if (sec[1] != '/')
646: prio += 10;
647: if (req->q.arch == NULL) {
1.21 schwarze 648: archprio =
1.59 schwarze 649: ((arch = strchr(sec + 1, '/'))
650: == NULL) ? 3 :
651: ((archend = strchr(arch + 1, '/'))
652: == NULL) ? 0 :
1.21 schwarze 653: strncmp(arch, "amd64/",
654: archend - arch) ? 2 : 1;
655: if (archprio < archpriouse) {
656: archpriouse = archprio;
657: priouse = prio;
658: iuse = i;
659: continue;
660: }
661: if (archprio > archpriouse)
662: continue;
663: }
1.10 schwarze 664: if (prio >= priouse)
665: continue;
666: priouse = prio;
667: iuse = i;
668: }
1.88 schwarze 669: resp_begin_html(200, NULL, r[iuse].file);
670: } else
671: resp_begin_html(200, NULL, NULL);
672:
673: resp_searchform(req,
674: req->q.equal || sz == 1 ? FOCUS_NONE : FOCUS_QUERY);
675:
676: if (sz > 1) {
677: puts("<table class=\"results\">");
678: for (i = 0; i < sz; i++) {
679: printf(" <tr>\n"
680: " <td>"
1.89 schwarze 681: "<a class=\"Xr\" href=\"/");
682: if (*scriptname != '\0')
683: printf("%s/", scriptname);
684: if (strcmp(req->q.manpath, req->p[0]))
685: printf("%s/", req->q.manpath);
686: printf("%s\">", r[i].file);
1.88 schwarze 687: html_print(r[i].names);
688: printf("</a></td>\n"
689: " <td><span class=\"Nd\">");
690: html_print(r[i].output);
691: puts("</span></td>\n"
692: " </tr>");
693: }
694: puts("</table>");
695: }
696:
697: if (req->q.equal || sz == 1) {
698: puts("<hr>");
1.10 schwarze 699: resp_show(req, r[iuse].file);
700: }
701:
1.1 schwarze 702: resp_end_html();
703: }
704:
705: static void
1.68 schwarze 706: resp_catman(const struct req *req, const char *file)
1.1 schwarze 707: {
708: FILE *f;
1.54 schwarze 709: char *p;
710: size_t sz;
711: ssize_t len;
1.1 schwarze 712: int i;
713: int italic, bold;
714:
1.54 schwarze 715: if ((f = fopen(file, "r")) == NULL) {
1.65 schwarze 716: puts("<p>You specified an invalid manual file.</p>");
1.1 schwarze 717: return;
718: }
719:
1.65 schwarze 720: puts("<div class=\"catman\">\n"
721: "<pre>");
1.1 schwarze 722:
1.54 schwarze 723: p = NULL;
724: sz = 0;
725:
726: while ((len = getline(&p, &sz, f)) != -1) {
1.1 schwarze 727: bold = italic = 0;
1.54 schwarze 728: for (i = 0; i < len - 1; i++) {
1.43 schwarze 729: /*
1.1 schwarze 730: * This means that the catpage is out of state.
731: * Ignore it and keep going (although the
732: * catpage is bogus).
733: */
734:
735: if ('\b' == p[i] || '\n' == p[i])
736: continue;
737:
738: /*
739: * Print a regular character.
740: * Close out any bold/italic scopes.
741: * If we're in back-space mode, make sure we'll
742: * have something to enter when we backspace.
743: */
744:
745: if ('\b' != p[i + 1]) {
746: if (italic)
1.65 schwarze 747: printf("</i>");
1.1 schwarze 748: if (bold)
1.65 schwarze 749: printf("</b>");
1.1 schwarze 750: italic = bold = 0;
751: html_putchar(p[i]);
752: continue;
1.54 schwarze 753: } else if (i + 2 >= len)
1.1 schwarze 754: continue;
755:
756: /* Italic mode. */
757:
758: if ('_' == p[i]) {
759: if (bold)
1.65 schwarze 760: printf("</b>");
1.1 schwarze 761: if ( ! italic)
1.65 schwarze 762: printf("<i>");
1.1 schwarze 763: bold = 0;
764: italic = 1;
765: i += 2;
766: html_putchar(p[i]);
767: continue;
768: }
769:
1.43 schwarze 770: /*
1.1 schwarze 771: * Handle funny behaviour troff-isms.
772: * These grok'd from the original man2html.c.
773: */
774:
775: if (('+' == p[i] && 'o' == p[i + 2]) ||
776: ('o' == p[i] && '+' == p[i + 2]) ||
777: ('|' == p[i] && '=' == p[i + 2]) ||
778: ('=' == p[i] && '|' == p[i + 2]) ||
779: ('*' == p[i] && '=' == p[i + 2]) ||
780: ('=' == p[i] && '*' == p[i + 2]) ||
781: ('*' == p[i] && '|' == p[i + 2]) ||
782: ('|' == p[i] && '*' == p[i + 2])) {
783: if (italic)
1.65 schwarze 784: printf("</i>");
1.1 schwarze 785: if (bold)
1.65 schwarze 786: printf("</b>");
1.1 schwarze 787: italic = bold = 0;
788: putchar('*');
789: i += 2;
790: continue;
791: } else if (('|' == p[i] && '-' == p[i + 2]) ||
792: ('-' == p[i] && '|' == p[i + 1]) ||
793: ('+' == p[i] && '-' == p[i + 1]) ||
794: ('-' == p[i] && '+' == p[i + 1]) ||
795: ('+' == p[i] && '|' == p[i + 1]) ||
796: ('|' == p[i] && '+' == p[i + 1])) {
797: if (italic)
1.65 schwarze 798: printf("</i>");
1.1 schwarze 799: if (bold)
1.65 schwarze 800: printf("</b>");
1.1 schwarze 801: italic = bold = 0;
802: putchar('+');
803: i += 2;
804: continue;
805: }
806:
807: /* Bold mode. */
1.43 schwarze 808:
1.1 schwarze 809: if (italic)
1.65 schwarze 810: printf("</i>");
1.1 schwarze 811: if ( ! bold)
1.65 schwarze 812: printf("<b>");
1.1 schwarze 813: bold = 1;
814: italic = 0;
815: i += 2;
816: html_putchar(p[i]);
817: }
818:
1.43 schwarze 819: /*
1.1 schwarze 820: * Clean up the last character.
1.43 schwarze 821: * We can get to a newline; don't print that.
1.1 schwarze 822: */
823:
824: if (italic)
1.65 schwarze 825: printf("</i>");
1.1 schwarze 826: if (bold)
1.65 schwarze 827: printf("</b>");
1.1 schwarze 828:
1.54 schwarze 829: if (i == len - 1 && p[i] != '\n')
1.1 schwarze 830: html_putchar(p[i]);
831:
832: putchar('\n');
833: }
1.54 schwarze 834: free(p);
1.1 schwarze 835:
1.65 schwarze 836: puts("</pre>\n"
837: "</div>");
1.1 schwarze 838:
839: fclose(f);
840: }
841:
842: static void
1.68 schwarze 843: resp_format(const struct req *req, const char *file)
1.1 schwarze 844: {
1.45 schwarze 845: struct manoutput conf;
1.1 schwarze 846: struct mparse *mp;
1.46 schwarze 847: struct roff_man *man;
1.1 schwarze 848: void *vp;
1.30 schwarze 849: int fd;
850: int usepath;
1.1 schwarze 851:
852: if (-1 == (fd = open(file, O_RDONLY, 0))) {
1.65 schwarze 853: puts("<p>You specified an invalid manual file.</p>");
1.1 schwarze 854: return;
855: }
856:
1.49 schwarze 857: mchars_alloc();
1.75 schwarze 858: mp = mparse_alloc(MPARSE_SO | MPARSE_UTF8 | MPARSE_LATIN1,
1.94 schwarze 859: MANDOCERR_MAX, NULL, MANDOC_OS_OTHER, req->q.manpath);
1.42 schwarze 860: mparse_readfd(mp, fd, file);
1.1 schwarze 861: close(fd);
862:
1.45 schwarze 863: memset(&conf, 0, sizeof(conf));
864: conf.fragment = 1;
1.84 schwarze 865: conf.style = mandoc_strdup(CSS_DIR "/mandoc.css");
1.30 schwarze 866: usepath = strcmp(req->q.manpath, req->p[0]);
1.90 schwarze 867: mandoc_asprintf(&conf.man, "/%s%s%s%s%%N.%%S",
868: scriptname, *scriptname == '\0' ? "" : "/",
1.61 schwarze 869: usepath ? req->q.manpath : "", usepath ? "/" : "");
1.1 schwarze 870:
1.47 schwarze 871: mparse_result(mp, &man, NULL);
872: if (man == NULL) {
1.67 schwarze 873: warnx("fatal mandoc error: %s/%s", req->q.manpath, file);
1.12 schwarze 874: pg_error_internal();
1.1 schwarze 875: mparse_free(mp);
1.49 schwarze 876: mchars_free();
1.1 schwarze 877: return;
878: }
879:
1.49 schwarze 880: vp = html_alloc(&conf);
1.1 schwarze 881:
1.50 schwarze 882: if (man->macroset == MACROSET_MDOC) {
883: mdoc_validate(man);
1.47 schwarze 884: html_mdoc(vp, man);
1.51 schwarze 885: } else {
886: man_validate(man);
1.1 schwarze 887: html_man(vp, man);
1.51 schwarze 888: }
1.1 schwarze 889:
890: html_free(vp);
891: mparse_free(mp);
1.49 schwarze 892: mchars_free();
1.45 schwarze 893: free(conf.man);
1.84 schwarze 894: free(conf.style);
1.1 schwarze 895: }
896:
897: static void
1.10 schwarze 898: resp_show(const struct req *req, const char *file)
899: {
1.16 schwarze 900:
901: if ('.' == file[0] && '/' == file[1])
1.11 schwarze 902: file += 2;
1.10 schwarze 903:
904: if ('c' == *file)
1.68 schwarze 905: resp_catman(req, file);
1.10 schwarze 906: else
1.68 schwarze 907: resp_format(req, file);
1.10 schwarze 908: }
909:
910: static void
1.24 schwarze 911: pg_show(struct req *req, const char *fullpath)
1.1 schwarze 912: {
1.24 schwarze 913: char *manpath;
914: const char *file;
1.1 schwarze 915:
1.24 schwarze 916: if ((file = strchr(fullpath, '/')) == NULL) {
1.12 schwarze 917: pg_error_badrequest(
1.1 schwarze 918: "You did not specify a page to show.");
919: return;
1.43 schwarze 920: }
1.24 schwarze 921: manpath = mandoc_strndup(fullpath, file - fullpath);
922: file++;
1.1 schwarze 923:
1.24 schwarze 924: if ( ! validate_manpath(req, manpath)) {
1.17 schwarze 925: pg_error_badrequest(
926: "You specified an invalid manpath.");
1.24 schwarze 927: free(manpath);
1.17 schwarze 928: return;
929: }
930:
1.1 schwarze 931: /*
932: * Begin by chdir()ing into the manpath.
933: * This way we can pick up the database files, which are
934: * relative to the manpath root.
935: */
936:
1.24 schwarze 937: if (chdir(manpath) == -1) {
1.67 schwarze 938: warn("chdir %s", manpath);
1.17 schwarze 939: pg_error_internal();
1.24 schwarze 940: free(manpath);
1.16 schwarze 941: return;
942: }
1.73 schwarze 943: free(manpath);
1.24 schwarze 944:
945: if ( ! validate_filename(file)) {
1.16 schwarze 946: pg_error_badrequest(
947: "You specified an invalid manual file.");
1.1 schwarze 948: return;
949: }
1.19 schwarze 950:
1.88 schwarze 951: resp_begin_html(200, NULL, file);
1.70 schwarze 952: resp_searchform(req, FOCUS_NONE);
1.24 schwarze 953: resp_show(req, file);
1.10 schwarze 954: resp_end_html();
1.1 schwarze 955: }
956:
957: static void
1.6 schwarze 958: pg_search(const struct req *req)
1.1 schwarze 959: {
960: struct mansearch search;
961: struct manpaths paths;
962: struct manpage *res;
1.36 schwarze 963: char **argv;
964: char *query, *rp, *wp;
1.1 schwarze 965: size_t ressz;
1.36 schwarze 966: int argc;
1.1 schwarze 967:
968: /*
969: * Begin by chdir()ing into the root of the manpath.
970: * This way we can pick up the database files, which are
971: * relative to the manpath root.
972: */
973:
1.67 schwarze 974: if (chdir(req->q.manpath) == -1) {
975: warn("chdir %s", req->q.manpath);
1.17 schwarze 976: pg_error_internal();
1.1 schwarze 977: return;
978: }
979:
980: search.arch = req->q.arch;
981: search.sec = req->q.sec;
1.35 schwarze 982: search.outkey = "Nd";
983: search.argmode = req->q.equal ? ARG_NAME : ARG_EXPR;
1.40 schwarze 984: search.firstmatch = 1;
1.1 schwarze 985:
986: paths.sz = 1;
987: paths.paths = mandoc_malloc(sizeof(char *));
988: paths.paths[0] = mandoc_strdup(".");
989:
990: /*
1.36 schwarze 991: * Break apart at spaces with backslash-escaping.
1.1 schwarze 992: */
993:
1.36 schwarze 994: argc = 0;
995: argv = NULL;
996: rp = query = mandoc_strdup(req->q.query);
997: for (;;) {
998: while (isspace((unsigned char)*rp))
999: rp++;
1000: if (*rp == '\0')
1001: break;
1002: argv = mandoc_reallocarray(argv, argc + 1, sizeof(char *));
1003: argv[argc++] = wp = rp;
1004: for (;;) {
1005: if (isspace((unsigned char)*rp)) {
1006: *wp = '\0';
1007: rp++;
1008: break;
1009: }
1010: if (rp[0] == '\\' && rp[1] != '\0')
1011: rp++;
1012: if (wp != rp)
1013: *wp = *rp;
1014: if (*rp == '\0')
1015: break;
1016: wp++;
1017: rp++;
1018: }
1.1 schwarze 1019: }
1020:
1.87 schwarze 1021: res = NULL;
1022: ressz = 0;
1023: if (req->isquery && req->q.equal && argc == 1)
1024: pg_redirect(req, argv[0]);
1025: else if (mansearch(&search, &paths, argc, argv, &res, &ressz) == 0)
1.12 schwarze 1026: pg_noresult(req, "You entered an invalid query.");
1.87 schwarze 1027: else if (ressz == 0)
1.12 schwarze 1028: pg_noresult(req, "No results found.");
1.1 schwarze 1029: else
1.12 schwarze 1030: pg_searchres(req, res, ressz);
1.1 schwarze 1031:
1.36 schwarze 1032: free(query);
1033: mansearch_free(res, ressz);
1.1 schwarze 1034: free(paths.paths[0]);
1035: free(paths.paths);
1036: }
1037:
1038: int
1039: main(void)
1040: {
1.6 schwarze 1041: struct req req;
1.33 schwarze 1042: struct itimerval itimer;
1.6 schwarze 1043: const char *path;
1.23 schwarze 1044: const char *querystring;
1.1 schwarze 1045: int i;
1.86 schwarze 1046:
1047: /*
1048: * The "rpath" pledge could be revoked after mparse_readfd()
1049: * if the file desciptor to "/footer.html" would be opened
1050: * up front, but it's probably not worth the complication
1051: * of the code it would cause: it would require scattering
1052: * pledge() calls in multiple low-level resp_*() functions.
1053: */
1054:
1055: if (pledge("stdio rpath", NULL) == -1) {
1056: warn("pledge");
1057: pg_error_internal();
1058: return EXIT_FAILURE;
1059: }
1.33 schwarze 1060:
1061: /* Poor man's ReDoS mitigation. */
1062:
1.38 schwarze 1063: itimer.it_value.tv_sec = 2;
1.33 schwarze 1064: itimer.it_value.tv_usec = 0;
1.38 schwarze 1065: itimer.it_interval.tv_sec = 2;
1.33 schwarze 1066: itimer.it_interval.tv_usec = 0;
1067: if (setitimer(ITIMER_VIRTUAL, &itimer, NULL) == -1) {
1.67 schwarze 1068: warn("setitimer");
1.20 schwarze 1069: pg_error_internal();
1.48 schwarze 1070: return EXIT_FAILURE;
1.20 schwarze 1071: }
1072:
1.1 schwarze 1073: /*
1.7 schwarze 1074: * First we change directory into the MAN_DIR so that
1.1 schwarze 1075: * subsequent scanning for manpath directories is rooted
1076: * relative to the same position.
1077: */
1078:
1.67 schwarze 1079: if (chdir(MAN_DIR) == -1) {
1080: warn("MAN_DIR: %s", MAN_DIR);
1.12 schwarze 1081: pg_error_internal();
1.48 schwarze 1082: return EXIT_FAILURE;
1.43 schwarze 1083: }
1.1 schwarze 1084:
1085: memset(&req, 0, sizeof(struct req));
1.57 schwarze 1086: req.q.equal = 1;
1.68 schwarze 1087: parse_manpath_conf(&req);
1.1 schwarze 1088:
1.56 schwarze 1089: /* Parse the path info and the query string. */
1.1 schwarze 1090:
1.56 schwarze 1091: if ((path = getenv("PATH_INFO")) == NULL)
1092: path = "";
1093: else if (*path == '/')
1094: path++;
1095:
1.63 schwarze 1096: if (*path != '\0') {
1.68 schwarze 1097: parse_path_info(&req, path);
1.92 schwarze 1098: if (req.q.manpath == NULL || req.q.sec == NULL ||
1099: *req.q.query == '\0' || access(path, F_OK) == -1)
1.63 schwarze 1100: path = "";
1.56 schwarze 1101: } else if ((querystring = getenv("QUERY_STRING")) != NULL)
1.68 schwarze 1102: parse_query_string(&req, querystring);
1.17 schwarze 1103:
1.56 schwarze 1104: /* Validate parsed data and add defaults. */
1105:
1.41 schwarze 1106: if (req.q.manpath == NULL)
1107: req.q.manpath = mandoc_strdup(req.p[0]);
1108: else if ( ! validate_manpath(&req, req.q.manpath)) {
1.17 schwarze 1109: pg_error_badrequest(
1110: "You specified an invalid manpath.");
1.48 schwarze 1111: return EXIT_FAILURE;
1.17 schwarze 1112: }
1.1 schwarze 1113:
1.97 ! schwarze 1114: if (req.q.arch != NULL && validate_arch(req.q.arch) == 0) {
1.20 schwarze 1115: pg_error_badrequest(
1116: "You specified an invalid architecture.");
1.48 schwarze 1117: return EXIT_FAILURE;
1.20 schwarze 1118: }
1119:
1.6 schwarze 1120: /* Dispatch to the three different pages. */
1.1 schwarze 1121:
1.6 schwarze 1122: if ('\0' != *path)
1123: pg_show(&req, path);
1.25 schwarze 1124: else if (NULL != req.q.query)
1.6 schwarze 1125: pg_search(&req);
1126: else
1.12 schwarze 1127: pg_index(&req);
1.1 schwarze 1128:
1.23 schwarze 1129: free(req.q.manpath);
1130: free(req.q.arch);
1131: free(req.q.sec);
1.25 schwarze 1132: free(req.q.query);
1.1 schwarze 1133: for (i = 0; i < (int)req.psz; i++)
1134: free(req.p[i]);
1135: free(req.p);
1.48 schwarze 1136: return EXIT_SUCCESS;
1.56 schwarze 1137: }
1138:
1139: /*
1140: * If PATH_INFO is not a file name, translate it to a query.
1141: */
1142: static void
1.68 schwarze 1143: parse_path_info(struct req *req, const char *path)
1.56 schwarze 1144: {
1.74 schwarze 1145: char *dir[4];
1146: int i;
1.56 schwarze 1147:
1.60 schwarze 1148: req->isquery = 0;
1.56 schwarze 1149: req->q.equal = 1;
1150: req->q.manpath = mandoc_strdup(path);
1.74 schwarze 1151: req->q.arch = NULL;
1.56 schwarze 1152:
1153: /* Mandatory manual page name. */
1154: if ((req->q.query = strrchr(req->q.manpath, '/')) == NULL) {
1155: req->q.query = req->q.manpath;
1156: req->q.manpath = NULL;
1157: } else
1158: *req->q.query++ = '\0';
1159:
1160: /* Optional trailing section. */
1161: if ((req->q.sec = strrchr(req->q.query, '.')) != NULL) {
1162: if(isdigit((unsigned char)req->q.sec[1])) {
1163: *req->q.sec++ = '\0';
1164: req->q.sec = mandoc_strdup(req->q.sec);
1165: } else
1166: req->q.sec = NULL;
1167: }
1168:
1169: /* Handle the case of name[.section] only. */
1.74 schwarze 1170: if (req->q.manpath == NULL)
1.56 schwarze 1171: return;
1.74 schwarze 1172: req->q.query = mandoc_strdup(req->q.query);
1173:
1174: /* Split directory components. */
1175: dir[i = 0] = req->q.manpath;
1176: while ((dir[i + 1] = strchr(dir[i], '/')) != NULL) {
1177: if (++i == 3) {
1178: pg_error_badrequest(
1179: "You specified too many directory components.");
1180: exit(EXIT_FAILURE);
1181: }
1182: *dir[i]++ = '\0';
1.56 schwarze 1183: }
1184:
1.74 schwarze 1185: /* Optional manpath. */
1186: if ((i = validate_manpath(req, req->q.manpath)) == 0)
1187: req->q.manpath = NULL;
1188: else if (dir[1] == NULL)
1189: return;
1.56 schwarze 1190:
1.74 schwarze 1191: /* Optional section. */
1192: if (strncmp(dir[i], "man", 3) == 0) {
1.66 schwarze 1193: free(req->q.sec);
1.74 schwarze 1194: req->q.sec = mandoc_strdup(dir[i++] + 3);
1.56 schwarze 1195: }
1.74 schwarze 1196: if (dir[i] == NULL) {
1197: if (req->q.manpath == NULL)
1198: free(dir[0]);
1199: return;
1200: }
1201: if (dir[i + 1] != NULL) {
1202: pg_error_badrequest(
1203: "You specified an invalid directory component.");
1204: exit(EXIT_FAILURE);
1205: }
1206:
1207: /* Optional architecture. */
1208: if (i) {
1209: req->q.arch = mandoc_strdup(dir[i]);
1210: if (req->q.manpath == NULL)
1211: free(dir[0]);
1212: } else
1213: req->q.arch = dir[0];
1.1 schwarze 1214: }
1215:
1216: /*
1217: * Scan for indexable paths.
1218: */
1219: static void
1.68 schwarze 1220: parse_manpath_conf(struct req *req)
1.1 schwarze 1221: {
1222: FILE *fp;
1223: char *dp;
1224: size_t dpsz;
1.54 schwarze 1225: ssize_t len;
1.1 schwarze 1226:
1.67 schwarze 1227: if ((fp = fopen("manpath.conf", "r")) == NULL) {
1228: warn("%s/manpath.conf", MAN_DIR);
1.14 schwarze 1229: pg_error_internal();
1230: exit(EXIT_FAILURE);
1231: }
1.1 schwarze 1232:
1.54 schwarze 1233: dp = NULL;
1234: dpsz = 0;
1235:
1236: while ((len = getline(&dp, &dpsz, fp)) != -1) {
1237: if (dp[len - 1] == '\n')
1238: dp[--len] = '\0';
1.1 schwarze 1239: req->p = mandoc_realloc(req->p,
1240: (req->psz + 1) * sizeof(char *));
1.20 schwarze 1241: if ( ! validate_urifrag(dp)) {
1.67 schwarze 1242: warnx("%s/manpath.conf contains "
1243: "unsafe path \"%s\"", MAN_DIR, dp);
1.20 schwarze 1244: pg_error_internal();
1245: exit(EXIT_FAILURE);
1246: }
1.67 schwarze 1247: if (strchr(dp, '/') != NULL) {
1248: warnx("%s/manpath.conf contains "
1249: "path with slash \"%s\"", MAN_DIR, dp);
1.20 schwarze 1250: pg_error_internal();
1251: exit(EXIT_FAILURE);
1252: }
1253: req->p[req->psz++] = dp;
1.54 schwarze 1254: dp = NULL;
1255: dpsz = 0;
1.14 schwarze 1256: }
1.54 schwarze 1257: free(dp);
1.14 schwarze 1258:
1.67 schwarze 1259: if (req->p == NULL) {
1260: warnx("%s/manpath.conf is empty", MAN_DIR);
1.14 schwarze 1261: pg_error_internal();
1262: exit(EXIT_FAILURE);
1.1 schwarze 1263: }
1264: }