diff options
| author | mrg <mrg@NetBSD.org> | 2015-12-29 04:21:46 +0000 |
|---|---|---|
| committer | mrg <mrg@NetBSD.org> | 2015-12-29 04:21:46 +0000 |
| commit | 9a464a4b6edc6691d5dbb00680a5e0bdf5e07d2c (patch) | |
| tree | bc13d82d8dea52ae75d8714b414ee7a2dd8363f0 /libexec | |
| parent | 6a4596b267dedc83f962b30852a4e93ee6387630 (diff) | |
- convert most asprintf() calls to bozoasprintf().
- don't call getpwuid(0) if we don't need to, or fail it it fails,
and remove the 'username' member of bozohttpd_t since it is not
used outside of bozo_setup().
Diffstat (limited to 'libexec')
| -rw-r--r-- | libexec/httpd/bozohttpd.c | 41 | ||||
| -rw-r--r-- | libexec/httpd/bozohttpd.h | 3 | ||||
| -rw-r--r-- | libexec/httpd/cgi-bozo.c | 13 | ||||
| -rw-r--r-- | libexec/httpd/dir-index-bozo.c | 7 |
4 files changed, 27 insertions, 37 deletions
diff --git a/libexec/httpd/bozohttpd.c b/libexec/httpd/bozohttpd.c index 54f157b4c4b..0424199e444 100644 --- a/libexec/httpd/bozohttpd.c +++ b/libexec/httpd/bozohttpd.c @@ -1,4 +1,4 @@ -/* $NetBSD: bozohttpd.c,v 1.74 2015/12/28 07:37:59 mrg Exp $ */ +/* $NetBSD: bozohttpd.c,v 1.75 2015/12/29 04:21:46 mrg Exp $ */ /* $eterna: bozohttpd.c,v 1.178 2011/11/18 09:21:15 mrg Exp $ */ @@ -383,11 +383,7 @@ addmerge_header(bozo_httpreq_t *request, char *val, /* yup, merge it in */ char *nval; - if (asprintf(&nval, "%s, %s", hdr->h_value, str) == -1) { - (void)bozo_http_error(httpd, 500, NULL, - "memory allocation failure"); - return NULL; - } + bozoasprintf(httpd, &nval, "%s, %s", hdr->h_value, str); free(hdr->h_value); hdr->h_value = nval; } else { @@ -955,9 +951,9 @@ handle_redirect(bozo_httpreq_t *request, const char *url, int absolute) const char *s; /* - * absolute redirect may specify own protocol i.e. to redirect to - * another schema like https:// or ftp://. Details: RFC 3986, section - * 3. + * absolute redirect may specify own protocol i.e. to redirect + * to another schema like https:// or ftp://. + * Details: RFC 3986, section 3. */ /* 1. check if url contains :// */ @@ -969,8 +965,8 @@ handle_redirect(bozo_httpreq_t *request, const char *url, int absolute) */ if (sep) { for (s = url; s != sep;) { - if (!isalnum((int)*s) && *s != '+' && *s != '-' && - *s != '.') + if (!isalnum((int)*s) && + *s != '+' && *s != '-' && *s != '.') break; if (++s == sep) { absproto = 1; @@ -2223,7 +2219,6 @@ bozo_setup(bozohttpd_t *httpd, bozoprefs_t *prefs, const char *vhost, if (vhost == NULL) { httpd->virthostname = bozomalloc(httpd, MAXHOSTNAMELEN+1); - /* XXX we do not check for FQDN here */ if (gethostname(httpd->virthostname, MAXHOSTNAMELEN+1) < 0) bozoerr(httpd, 1, "gethostname"); httpd->virthostname[MAXHOSTNAMELEN] = '\0'; @@ -2298,20 +2293,16 @@ bozo_setup(bozohttpd_t *httpd, bozoprefs_t *prefs, const char *vhost, bozo_ssl_init(httpd); bozo_daemon_init(httpd); - if ((username = bozo_get_pref(prefs, "username")) == NULL) { - if ((pw = getpwuid(uid = 0)) == NULL) - bozoerr(httpd, 1, "getpwuid(0): %s", strerror(errno)); - httpd->username = bozostrdup(httpd, NULL, pw->pw_name); - } else { - httpd->username = bozostrdup(httpd, NULL, username); - if ((pw = getpwnam(httpd->username)) == NULL) - bozoerr(httpd, 1, "getpwnam(%s): %s", httpd->username, - strerror(errno)); + username = bozo_get_pref(prefs, "username"); + if (username != NULL) { + if ((pw = getpwnam(username)) == NULL) + bozoerr(httpd, 1, "getpwnam(%s): %s", username, + strerror(errno)); if (initgroups(pw->pw_name, pw->pw_gid) == -1) bozoerr(httpd, 1, "initgroups: %s", strerror(errno)); if (setgid(pw->pw_gid) == -1) bozoerr(httpd, 1, "setgid(%u): %s", pw->pw_gid, - strerror(errno)); + strerror(errno)); uid = pw->pw_uid; } /* @@ -2327,10 +2318,8 @@ bozo_setup(bozohttpd_t *httpd, bozoprefs_t *prefs, const char *vhost, strerror(errno)); } - if (username != NULL) - if (setuid(uid) == -1) - bozoerr(httpd, 1, "setuid(%d): %s", uid, - strerror(errno)); + if (username != NULL && setuid(uid) == -1) + bozoerr(httpd, 1, "setuid(%d): %s", uid, strerror(errno)); /* * prevent info leakage between different compartments. diff --git a/libexec/httpd/bozohttpd.h b/libexec/httpd/bozohttpd.h index 669fa745188..50c7b7f76af 100644 --- a/libexec/httpd/bozohttpd.h +++ b/libexec/httpd/bozohttpd.h @@ -1,4 +1,4 @@ -/* $NetBSD: bozohttpd.h,v 1.42 2015/12/28 07:37:59 mrg Exp $ */ +/* $NetBSD: bozohttpd.h,v 1.43 2015/12/29 04:21:46 mrg Exp $ */ /* $eterna: bozohttpd.h,v 1.39 2011/11/18 09:21:15 mrg Exp $ */ @@ -90,7 +90,6 @@ typedef struct bozo_consts_t { /* this structure encapsulates all the bozo flags and control vars */ typedef struct bozohttpd_t { char *rootdir; /* root directory */ - char *username; /* username to switch to */ int numeric; /* avoid gethostby*() */ char *virtbase; /* virtual directory base */ int unknown_slash; /* unknown vhosts go to normal slashdir */ diff --git a/libexec/httpd/cgi-bozo.c b/libexec/httpd/cgi-bozo.c index c2f554ab917..e50353ac4c2 100644 --- a/libexec/httpd/cgi-bozo.c +++ b/libexec/httpd/cgi-bozo.c @@ -1,4 +1,4 @@ -/* $NetBSD: cgi-bozo.c,v 1.30 2015/12/28 07:37:59 mrg Exp $ */ +/* $NetBSD: cgi-bozo.c,v 1.31 2015/12/29 04:21:46 mrg Exp $ */ /* $eterna: cgi-bozo.c,v 1.40 2011/11/18 09:21:15 mrg Exp $ */ @@ -274,7 +274,7 @@ bozo_process_cgi(bozo_httpreq_t *request) if (uri[0] == '/') file = bozostrdup(httpd, request, uri); else - asprintf(&file, "/%s", uri); + bozoasprintf(httpd, &file, "/%s", uri); if (file == NULL) return 0; @@ -283,7 +283,10 @@ bozo_process_cgi(bozo_httpreq_t *request) else query = NULL; - asprintf(&url, "%s%s%s", file, query ? "?" : "", query ? query : ""); + bozoasprintf(httpd, &url, "%s%s%s", + file, + query ? "?" : "", + query ? query : ""); if (url == NULL) goto out; debug((httpd, DEBUG_NORMAL, "bozo_process_cgi: url `%s'", url)); @@ -420,8 +423,8 @@ bozo_process_cgi(bozo_httpreq_t *request) bozo_setenv(httpd, "REMOTE_ADDR", request->hr_remoteaddr, curenvp++); /* - * XXX Apache does this when invoking content handlers, and PHP - * XXX 5.3 requires it as a "security" measure. + * Apache does this when invoking content handlers, and PHP + * 5.3 requires it as a "security" measure. */ if (cgihandler) bozo_setenv(httpd, "REDIRECT_STATUS", "200", curenvp++); diff --git a/libexec/httpd/dir-index-bozo.c b/libexec/httpd/dir-index-bozo.c index ec9608f38b9..c3a322a3e65 100644 --- a/libexec/httpd/dir-index-bozo.c +++ b/libexec/httpd/dir-index-bozo.c @@ -1,4 +1,4 @@ -/* $NetBSD: dir-index-bozo.c,v 1.24 2015/12/28 07:37:59 mrg Exp $ */ +/* $NetBSD: dir-index-bozo.c,v 1.25 2015/12/29 04:21:46 mrg Exp $ */ /* $eterna: dir-index-bozo.c,v 1.20 2011/11/18 09:21:15 mrg Exp $ */ @@ -110,9 +110,8 @@ bozo_dir_index(bozo_httpreq_t *request, const char *dirpath, int isindex) #ifndef NO_USER_SUPPORT if (request->hr_user) { - if (asprintf(&printname, "~%s/%s", request->hr_user, - request->hr_file) < 0) - bozoerr(httpd, 1, "asprintf"); + bozoasprintf(httpd, &printname, "~%s/%s", + request->hr_user, request->hr_file); } else printname = bozostrdup(httpd, request, request->hr_file); #else |
