=================================================================== RCS file: /cvs/mandoc/cgi.c,v retrieving revision 1.43 retrieving revision 1.47 diff -u -p -r1.43 -r1.47 --- mandoc/cgi.c 2012/03/25 00:46:39 1.43 +++ mandoc/cgi.c 2014/01/05 20:41:04 1.47 @@ -1,4 +1,4 @@ -/* $Id: cgi.c,v 1.43 2012/03/25 00:46:39 kristaps Exp $ */ +/* $Id: cgi.c,v 1.47 2014/01/05 20:41:04 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons * @@ -18,7 +18,6 @@ #include "config.h" #endif -#include #include #include @@ -35,6 +34,13 @@ #include #include +#if defined(__sun) +/* for stat() */ +#include +#include +#include +#endif + #include "apropos_db.h" #include "mandoc.h" #include "mdoc.h" @@ -43,7 +49,7 @@ #include "manpath.h" #include "mandocdb.h" -#ifdef __linux__ +#if defined(__linux__) || defined(__sun) # include #else # include @@ -726,14 +732,14 @@ format(const struct req *req, const char *file) struct man *man; void *vp; enum mandoclevel rc; - char opts[MAXPATHLEN + 128]; + char opts[PATH_MAX + 128]; if (-1 == (fd = open(file, O_RDONLY, 0))) { resp_baddb(); return; } - mp = mparse_alloc(MPARSE_AUTO, MANDOCLEVEL_FATAL, NULL, NULL); + mp = mparse_alloc(MPARSE_AUTO, MANDOCLEVEL_FATAL, NULL, NULL, 0); rc = mparse_readfd(mp, fd, file); close(fd); @@ -777,7 +783,7 @@ pg_show(const struct req *req, char *path) struct manpaths ps; size_t sz; char *sub; - char file[MAXPATHLEN]; + char file[PATH_MAX]; const char *cp; int rc, catm; unsigned int vol, rec, mr; @@ -831,10 +837,10 @@ pg_show(const struct req *req, char *path) goto out; } - sz = strlcpy(file, ps.paths[vol], MAXPATHLEN); - assert(sz < MAXPATHLEN); - strlcat(file, "/", MAXPATHLEN); - strlcat(file, MANDOC_IDX, MAXPATHLEN); + sz = strlcpy(file, ps.paths[vol], PATH_MAX); + assert(sz < PATH_MAX); + strlcat(file, "/", PATH_MAX); + strlcat(file, MANDOC_IDX, PATH_MAX); /* Open the index recno(3) database. */ @@ -863,8 +869,8 @@ pg_show(const struct req *req, char *path) resp_baddb(); else { file[(int)sz] = '\0'; - strlcat(file, "/", MAXPATHLEN); - strlcat(file, cp, MAXPATHLEN); + strlcat(file, "/", PATH_MAX); + strlcat(file, cp, PATH_MAX); if (catm) catman(req, file); else @@ -973,7 +979,7 @@ int main(void) { int i; - char buf[MAXPATHLEN]; + char buf[PATH_MAX]; DIR *cwd; struct req req; char *p, *path, *subpath; @@ -1010,7 +1016,7 @@ main(void) memset(&req, 0, sizeof(struct req)); - strlcpy(buf, ".", MAXPATHLEN); + strlcpy(buf, ".", PATH_MAX); pathgen(cwd, buf, &req); closedir(cwd); @@ -1098,11 +1104,20 @@ static int pathstop(DIR *dir) { struct dirent *d; +#if defined(__sun) + struct stat sb; +#endif - while (NULL != (d = readdir(dir))) + while (NULL != (d = readdir(dir))) { +#if defined(__sun) + stat(d->d_name, &sb); + if (S_IFREG & sb.st_mode) +#else if (DT_REG == d->d_type) +#endif if (0 == strcmp(d->d_name, "catman.conf")) return(1); + } return(0); } @@ -1119,9 +1134,12 @@ pathgen(DIR *dir, char *path, struct req *req) DIR *cd; int rc; size_t sz, ssz; +#if defined(__sun) + struct stat sb; +#endif - sz = strlcat(path, "/", MAXPATHLEN); - if (sz >= MAXPATHLEN) { + sz = strlcat(path, "/", PATH_MAX); + if (sz >= PATH_MAX) { fprintf(stderr, "%s: Path too long", path); return; } @@ -1134,13 +1152,19 @@ pathgen(DIR *dir, char *path, struct req *req) rc = 0; while (0 == rc && NULL != (d = readdir(dir))) { - if (DT_DIR != d->d_type || strcmp(d->d_name, "etc")) +#if defined(__sun) + stat(d->d_name, &sb); + if (!(S_IFDIR & sb.st_mode) +#else + if (DT_DIR != d->d_type +#endif + || strcmp(d->d_name, "etc")) continue; path[(int)sz] = '\0'; - ssz = strlcat(path, d->d_name, MAXPATHLEN); + ssz = strlcat(path, d->d_name, PATH_MAX); - if (ssz >= MAXPATHLEN) { + if (ssz >= PATH_MAX) { fprintf(stderr, "%s: Path too long", path); return; } else if (NULL == (cd = opendir(path))) { @@ -1183,13 +1207,19 @@ pathgen(DIR *dir, char *path, struct req *req) rewinddir(dir); while (NULL != (d = readdir(dir))) { - if (DT_DIR != d->d_type || '.' == d->d_name[0]) +#if defined(__sun) + stat(d->d_name, &sb); + if (!(S_IFDIR & sb.st_mode) +#else + if (DT_DIR != d->d_type +#endif + || '.' == d->d_name[0]) continue; path[(int)sz] = '\0'; - ssz = strlcat(path, d->d_name, MAXPATHLEN); + ssz = strlcat(path, d->d_name, PATH_MAX); - if (ssz >= MAXPATHLEN) { + if (ssz >= PATH_MAX) { fprintf(stderr, "%s: Path too long", path); return; } else if (NULL == (cd = opendir(path))) {