version 1.78, 2014/07/21 15:45:17 |
version 1.81, 2014/07/24 08:26:57 |
Line 71 static void pg_noresult(const struct req *, const ch |
|
Line 71 static void pg_noresult(const struct req *, const ch |
|
static void pg_search(const struct req *); |
static void pg_search(const struct req *); |
static void pg_searchres(const struct req *, |
static void pg_searchres(const struct req *, |
struct manpage *, size_t); |
struct manpage *, size_t); |
static void pg_show(const struct req *, const char *); |
static void pg_show(struct req *, const char *); |
static void resp_begin_html(int, const char *); |
static void resp_begin_html(int, const char *); |
static void resp_begin_http(int, const char *); |
static void resp_begin_http(int, const char *); |
static void resp_end_html(void); |
static void resp_end_html(void); |
Line 422 resp_searchform(const struct req *req) |
|
Line 422 resp_searchform(const struct req *req) |
|
|
|
/* Write architecture selector. */ |
/* Write architecture selector. */ |
|
|
puts("<SELECT NAME=\"arch\">"); |
printf( "<SELECT NAME=\"arch\">\n" |
|
"<OPTION VALUE=\"default\""); |
|
if (NULL == req->q.arch) |
|
printf(" SELECTED"); |
|
puts(">All Architectures</OPTION>"); |
for (i = 0; i < arch_MAX; i++) { |
for (i = 0; i < arch_MAX; i++) { |
printf("<OPTION VALUE=\"%s\"", arch_names[i]); |
printf("<OPTION VALUE=\"%s\"", arch_names[i]); |
if (NULL != req->q.arch && |
if (NULL != req->q.arch && |
Line 467 resp_searchform(const struct req *req) |
|
Line 471 resp_searchform(const struct req *req) |
|
} |
} |
|
|
static int |
static int |
|
validate_urifrag(const char *frag) |
|
{ |
|
|
|
while ('\0' != *frag) { |
|
if ( ! (isalnum((unsigned char)*frag) || |
|
'-' == *frag || '.' == *frag || |
|
'/' == *frag || '_' == *frag)) |
|
return(0); |
|
frag++; |
|
} |
|
return(1); |
|
} |
|
|
|
static int |
validate_manpath(const struct req *req, const char* manpath) |
validate_manpath(const struct req *req, const char* manpath) |
{ |
{ |
size_t i; |
size_t i; |
Line 545 pg_error_internal(void) |
|
Line 563 pg_error_internal(void) |
|
static void |
static void |
pg_searchres(const struct req *req, struct manpage *r, size_t sz) |
pg_searchres(const struct req *req, struct manpage *r, size_t sz) |
{ |
{ |
|
char *arch, *archend; |
size_t i, iuse, isec; |
size_t i, iuse, isec; |
|
int archprio, archpriouse; |
int prio, priouse; |
int prio, priouse; |
char sec; |
char sec; |
|
|
Line 608 pg_searchres(const struct req *req, struct manpage *r, |
|
Line 628 pg_searchres(const struct req *req, struct manpage *r, |
|
puts("<HR>"); |
puts("<HR>"); |
iuse = 0; |
iuse = 0; |
priouse = 10; |
priouse = 10; |
|
archpriouse = 3; |
for (i = 0; i < sz; i++) { |
for (i = 0; i < sz; i++) { |
isec = strcspn(r[i].file, "123456789"); |
isec = strcspn(r[i].file, "123456789"); |
sec = r[i].file[isec]; |
sec = r[i].file[isec]; |
if ('\0' == sec) |
if ('\0' == sec) |
continue; |
continue; |
prio = sec_prios[sec - '1']; |
prio = sec_prios[sec - '1']; |
|
if (NULL == req->q.arch) { |
|
archprio = |
|
(NULL == (arch = strchr( |
|
r[i].file + isec, '/'))) ? 3 : |
|
(NULL == (archend = strchr( |
|
arch + 1, '/'))) ? 0 : |
|
strncmp(arch, "amd64/", |
|
archend - arch) ? 2 : 1; |
|
if (archprio < archpriouse) { |
|
archpriouse = archprio; |
|
priouse = prio; |
|
iuse = i; |
|
continue; |
|
} |
|
if (archprio > archpriouse) |
|
continue; |
|
} |
if (prio >= priouse) |
if (prio >= priouse) |
continue; |
continue; |
priouse = prio; |
priouse = prio; |
Line 785 format(const struct req *req, const char *file) |
|
Line 823 format(const struct req *req, const char *file) |
|
return; |
return; |
} |
} |
|
|
snprintf(opts, sizeof(opts), |
snprintf(opts, sizeof(opts), "fragment,man=%s?" |
"fragment,man=%s?query=%%N&sec=%%S", |
"manpath=%s&query=%%N&sec=%%S&arch=%s", |
scriptname); |
scriptname, req->q.manpath, |
|
req->q.arch ? req->q.arch : ""); |
|
|
mparse_result(mp, &mdoc, &man, NULL); |
mparse_result(mp, &mdoc, &man, NULL); |
if (NULL == man && NULL == mdoc) { |
if (NULL == man && NULL == mdoc) { |
Line 823 resp_show(const struct req *req, const char *file) |
|
Line 862 resp_show(const struct req *req, const char *file) |
|
} |
} |
|
|
static void |
static void |
pg_show(const struct req *req, const char *path) |
pg_show(struct req *req, const char *path) |
{ |
{ |
char *sub; |
char *sub; |
|
|
Line 859 pg_show(const struct req *req, const char *path) |
|
Line 898 pg_show(const struct req *req, const char *path) |
|
return; |
return; |
} |
} |
|
|
|
if (strcmp(path, "mandoc")) |
|
req->q.manpath = path; |
|
|
resp_begin_html(200, NULL); |
resp_begin_html(200, NULL); |
resp_searchform(req); |
resp_searchform(req); |
resp_show(req, sub); |
resp_show(req, sub); |
|
|
if (NULL == (scriptname = getenv("SCRIPT_NAME"))) |
if (NULL == (scriptname = getenv("SCRIPT_NAME"))) |
scriptname = ""; |
scriptname = ""; |
|
|
|
if ( ! validate_urifrag(scriptname)) { |
|
fprintf(stderr, "unsafe SCRIPT_NAME \"%s\"\n", |
|
scriptname); |
|
pg_error_internal(); |
|
return(EXIT_FAILURE); |
|
} |
|
|
/* |
/* |
* First we change directory into the MAN_DIR so that |
* First we change directory into the MAN_DIR so that |
* subsequent scanning for manpath directories is rooted |
* subsequent scanning for manpath directories is rooted |
|
|
return(EXIT_FAILURE); |
return(EXIT_FAILURE); |
} |
} |
|
|
|
if ( ! (NULL == req.q.arch || validate_urifrag(req.q.arch))) { |
|
pg_error_badrequest( |
|
"You specified an invalid architecture."); |
|
return(EXIT_FAILURE); |
|
} |
|
|
/* Dispatch to the three different pages. */ |
/* Dispatch to the three different pages. */ |
|
|
path = getenv("PATH_INFO"); |
path = getenv("PATH_INFO"); |
Line 1034 pathgen(struct req *req) |
|
Line 1089 pathgen(struct req *req) |
|
dpsz--; |
dpsz--; |
req->p = mandoc_realloc(req->p, |
req->p = mandoc_realloc(req->p, |
(req->psz + 1) * sizeof(char *)); |
(req->psz + 1) * sizeof(char *)); |
req->p[req->psz++] = mandoc_strndup(dp, dpsz); |
dp = mandoc_strndup(dp, dpsz); |
|
if ( ! validate_urifrag(dp)) { |
|
fprintf(stderr, "%s/manpath.conf contains " |
|
"unsafe path \"%s\"\n", MAN_DIR, dp); |
|
pg_error_internal(); |
|
exit(EXIT_FAILURE); |
|
} |
|
if (NULL != strchr(dp, '/')) { |
|
fprintf(stderr, "%s/manpath.conf contains " |
|
"path with slash \"%s\"\n", MAN_DIR, dp); |
|
pg_error_internal(); |
|
exit(EXIT_FAILURE); |
|
} |
|
req->p[req->psz++] = dp; |
} |
} |
|
|
if ( req->p == NULL ) { |
if ( req->p == NULL ) { |