]> granicus.if.org Git - apache/blob - server/util_script.c
b3b3593ded4a0576679a1d8d92f0dca72041c110
[apache] / server / util_script.c
1 /* ====================================================================
2  * The Apache Software License, Version 1.1
3  *
4  * Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
5  * reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in
16  *    the documentation and/or other materials provided with the
17  *    distribution.
18  *
19  * 3. The end-user documentation included with the redistribution,
20  *    if any, must include the following acknowledgment:
21  *       "This product includes software developed by the
22  *        Apache Software Foundation (http://www.apache.org/)."
23  *    Alternately, this acknowledgment may appear in the software itself,
24  *    if and wherever such third-party acknowledgments normally appear.
25  *
26  * 4. The names "Apache" and "Apache Software Foundation" must
27  *    not be used to endorse or promote products derived from this
28  *    software without prior written permission. For written
29  *    permission, please contact apache@apache.org.
30  *
31  * 5. Products derived from this software may not be called "Apache",
32  *    nor may "Apache" appear in their name, without prior written
33  *    permission of the Apache Software Foundation.
34  *
35  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46  * SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of the Apache Software Foundation.  For more
51  * information on the Apache Software Foundation, please see
52  * <http://www.apache.org/>.
53  *
54  * Portions of this software are based upon public domain software
55  * originally written at the National Center for Supercomputing Applications,
56  * University of Illinois, Urbana-Champaign.
57  */
58
59 #include "apr.h"
60 #include "apr_lib.h"
61 #include "apr_strings.h"
62
63 #define APR_WANT_STRFUNC
64 #include "apr_want.h"
65
66 #if APR_HAVE_STDLIB_H
67 #include <stdlib.h>
68 #endif
69
70 #define CORE_PRIVATE
71 #include "ap_config.h"
72 #include "httpd.h"
73 #include "http_config.h"
74 #include "http_main.h"
75 #include "http_log.h"
76 #include "http_core.h"
77 #include "http_protocol.h"
78 #include "http_request.h"       /* for sub_req_lookup_uri() */
79 #include "util_script.h"
80 #include "apr_date.h"           /* For apr_date_parse_http() */
81 #include "util_ebcdic.h"
82
83 #ifdef OS2
84 #define INCL_DOS
85 #include <os2.h>
86 #endif
87
88 /*
89  * Various utility functions which are common to a whole lot of
90  * script-type extensions mechanisms, and might as well be gathered
91  * in one place (if only to avoid creating inter-module dependancies
92  * where there don't have to be).
93  */
94
95 #define MALFORMED_MESSAGE "malformed header from script. Bad header="
96 #define MALFORMED_HEADER_LENGTH_TO_SHOW 30
97
98 static char *http2env(apr_pool_t *a, const char *w)
99 {
100     char *res = (char *)apr_palloc(a, sizeof("HTTP_") + strlen(w));
101     char *cp = res;
102     char c;
103
104     *cp++ = 'H';
105     *cp++ = 'T';
106     *cp++ = 'T';
107     *cp++ = 'P';
108     *cp++ = '_';
109
110     while ((c = *w++) != 0) {
111         if (!apr_isalnum(c)) {
112             *cp++ = '_';
113         }
114         else {
115             *cp++ = apr_toupper(c);
116         }
117     }
118     *cp = 0;
119  
120     return res;
121 }
122
123 AP_DECLARE(char **) ap_create_environment(apr_pool_t *p, apr_table_t *t)
124 {
125     const apr_array_header_t *env_arr = apr_table_elts(t);
126     const apr_table_entry_t *elts = (const apr_table_entry_t *) env_arr->elts;
127     char **env = (char **) apr_palloc(p, (env_arr->nelts + 2) * sizeof(char *));
128     int i, j;
129     char *tz;
130     char *whack;
131
132     j = 0;
133     if (!apr_table_get(t, "TZ")) {
134         tz = getenv("TZ");
135         if (tz != NULL) {
136             env[j++] = apr_pstrcat(p, "TZ=", tz, NULL);
137         }
138     }
139     for (i = 0; i < env_arr->nelts; ++i) {
140         if (!elts[i].key) {
141             continue;
142         }
143         env[j] = apr_pstrcat(p, elts[i].key, "=", elts[i].val, NULL);
144         whack = env[j];
145         if (apr_isdigit(*whack)) {
146             *whack++ = '_';
147         }
148         while (*whack != '=') {
149             if (!apr_isalnum(*whack) && *whack != '_') {
150                 *whack = '_';
151             }
152             ++whack;
153         }
154         ++j;
155     }
156
157     env[j] = NULL;
158     return env;
159 }
160
161 AP_DECLARE(void) ap_add_common_vars(request_rec *r)
162 {
163     apr_table_t *e;
164     server_rec *s = r->server;
165     conn_rec *c = r->connection;
166     const char *rem_logname;
167     char *env_path;
168 #if defined(WIN32) || defined(OS2) || defined(BEOS)
169     char *env_temp;
170 #endif
171     const char *host;
172     const apr_array_header_t *hdrs_arr = apr_table_elts(r->headers_in);
173     const apr_table_entry_t *hdrs = (const apr_table_entry_t *) hdrs_arr->elts;
174     int i;
175     apr_port_t rport;
176
177     /* use a temporary apr_table_t which we'll overlap onto
178      * r->subprocess_env later
179      */
180     e = apr_table_make(r->pool, 25 + hdrs_arr->nelts);
181
182     /* First, add environment vars from headers... this is as per
183      * CGI specs, though other sorts of scripting interfaces see
184      * the same vars...
185      */
186
187     for (i = 0; i < hdrs_arr->nelts; ++i) {
188         if (!hdrs[i].key) {
189             continue;
190         }
191
192         /* A few headers are special cased --- Authorization to prevent
193          * rogue scripts from capturing passwords; content-type and -length
194          * for no particular reason.
195          */
196
197         if (!strcasecmp(hdrs[i].key, "Content-type")) {
198             apr_table_addn(e, "CONTENT_TYPE", hdrs[i].val);
199         }
200         else if (!strcasecmp(hdrs[i].key, "Content-length")) {
201             apr_table_addn(e, "CONTENT_LENGTH", hdrs[i].val);
202         }
203         /*
204          * You really don't want to disable this check, since it leaves you
205          * wide open to CGIs stealing passwords and people viewing them
206          * in the environment with "ps -e".  But, if you must...
207          */
208 #ifndef SECURITY_HOLE_PASS_AUTHORIZATION
209         else if (!strcasecmp(hdrs[i].key, "Authorization") 
210                  || !strcasecmp(hdrs[i].key, "Proxy-Authorization")) {
211             continue;
212         }
213 #endif
214         else {
215             apr_table_addn(e, http2env(r->pool, hdrs[i].key), hdrs[i].val);
216         }
217     }
218
219     if (!(env_path = getenv("PATH"))) {
220         env_path = DEFAULT_PATH;
221     }
222     apr_table_addn(e, "PATH", apr_pstrdup(r->pool, env_path));
223
224 #ifdef WIN32
225     if (env_temp = getenv("SystemRoot")) {
226         apr_table_addn(e, "SystemRoot", env_temp);         
227     }
228     if (env_temp = getenv("COMSPEC")) {
229         apr_table_addn(e, "COMSPEC", env_temp);            
230     }
231     if (env_temp = getenv("PATHEXT")) {
232         apr_table_addn(e, "PATHEXT", env_temp);            
233     }
234     if (env_temp = getenv("WINDIR")) {
235         apr_table_addn(e, "WINDIR", env_temp);
236     }
237 #endif
238
239 #ifdef OS2
240     if ((env_temp = getenv("COMSPEC")) != NULL) {
241         apr_table_addn(e, "COMSPEC", env_temp);            
242     }
243     if ((env_temp = getenv("ETC")) != NULL) {
244         apr_table_addn(e, "ETC", env_temp);            
245     }
246     if ((env_temp = getenv("DPATH")) != NULL) {
247         apr_table_addn(e, "DPATH", env_temp);            
248     }
249     if ((env_temp = getenv("PERLLIB_PREFIX")) != NULL) {
250         apr_table_addn(e, "PERLLIB_PREFIX", env_temp);            
251     }
252 #endif
253
254 #ifdef BEOS
255     if ((env_temp = getenv("LIBRARY_PATH")) != NULL) {
256         apr_table_addn(e, "LIBRARY_PATH", env_temp);            
257     }
258 #endif
259
260     apr_table_addn(e, "SERVER_SIGNATURE", ap_psignature("", r));
261     apr_table_addn(e, "SERVER_SOFTWARE", ap_get_server_version());
262     apr_table_addn(e, "SERVER_NAME", ap_get_server_name(r));
263     apr_table_addn(e, "SERVER_ADDR", r->connection->local_ip);  /* Apache */
264     apr_table_addn(e, "SERVER_PORT",
265                   apr_psprintf(r->pool, "%u", ap_get_server_port(r)));
266     host = ap_get_remote_host(c, r->per_dir_config, REMOTE_HOST, NULL);
267     if (host) {
268         apr_table_addn(e, "REMOTE_HOST", host);
269     }
270     apr_table_addn(e, "REMOTE_ADDR", c->remote_ip);
271     apr_table_addn(e, "DOCUMENT_ROOT", ap_document_root(r));    /* Apache */
272     apr_table_addn(e, "SERVER_ADMIN", s->server_admin); /* Apache */
273     apr_table_addn(e, "SCRIPT_FILENAME", r->filename);  /* Apache */
274
275     apr_sockaddr_port_get(&rport, c->remote_addr);
276     apr_table_addn(e, "REMOTE_PORT", apr_psprintf(r->pool, "%d", rport));
277
278     if (r->user) {
279         apr_table_addn(e, "REMOTE_USER", r->user);
280     }
281     if (r->ap_auth_type) {
282         apr_table_addn(e, "AUTH_TYPE", r->ap_auth_type);
283     }
284     rem_logname = ap_get_remote_logname(r);
285     if (rem_logname) {
286         apr_table_addn(e, "REMOTE_IDENT", apr_pstrdup(r->pool, rem_logname));
287     }
288
289     /* Apache custom error responses. If we have redirected set two new vars */
290
291     if (r->prev) {
292         if (r->prev->args) {
293             apr_table_addn(e, "REDIRECT_QUERY_STRING", r->prev->args);
294         }
295         if (r->prev->uri) {
296             apr_table_addn(e, "REDIRECT_URL", r->prev->uri);
297         }
298     }
299
300     apr_table_overlap(r->subprocess_env, e, APR_OVERLAP_TABLES_SET);
301 }
302
303 /* This "cute" little function comes about because the path info on
304  * filenames and URLs aren't always the same. So we take the two,
305  * and find as much of the two that match as possible.
306  */
307
308 AP_DECLARE(int) ap_find_path_info(const char *uri, const char *path_info)
309 {
310     int lu = strlen(uri);
311     int lp = strlen(path_info);
312
313     while (lu-- && lp-- && uri[lu] == path_info[lp]);
314
315     if (lu == -1) {
316         lu = 0;
317     }
318
319     while (uri[lu] != '\0' && uri[lu] != '/') {
320         lu++;
321     }
322     return lu;
323 }
324
325 /* Obtain the Request-URI from the original request-line, returning
326  * a new string from the request pool containing the URI or "".
327  */
328 static char *original_uri(request_rec *r)
329 {
330     char *first, *last;
331
332     if (r->the_request == NULL) {
333         return (char *) apr_pcalloc(r->pool, 1);
334     }
335
336     first = r->the_request;     /* use the request-line */
337
338     while (*first && !apr_isspace(*first)) {
339         ++first;                /* skip over the method */
340     }
341     while (apr_isspace(*first)) {
342         ++first;                /*   and the space(s)   */
343     }
344
345     last = first;
346     while (*last && !apr_isspace(*last)) {
347         ++last;                 /* end at next whitespace */
348     }
349
350     return apr_pstrndup(r->pool, first, last - first);
351 }
352
353 AP_DECLARE(void) ap_add_cgi_vars(request_rec *r)
354 {
355     apr_table_t *e = r->subprocess_env;
356
357     apr_table_setn(e, "GATEWAY_INTERFACE", "CGI/1.1");
358     apr_table_setn(e, "SERVER_PROTOCOL", r->protocol);
359     apr_table_setn(e, "REQUEST_METHOD", r->method);
360     apr_table_setn(e, "QUERY_STRING", r->args ? r->args : "");
361     apr_table_setn(e, "REQUEST_URI", original_uri(r)); 
362
363     /* Note that the code below special-cases scripts run from includes,
364      * because it "knows" that the sub_request has been hacked to have the
365      * args and path_info of the original request, and not any that may have
366      * come with the script URI in the include command.  Ugh.
367      */
368
369     if (!strcmp(r->protocol, "INCLUDED")) {
370         apr_table_setn(e, "SCRIPT_NAME", r->uri);
371         if (r->path_info && *r->path_info) {
372             apr_table_setn(e, "PATH_INFO", r->path_info);
373         }
374     }
375     else if (!r->path_info || !*r->path_info) {
376         apr_table_setn(e, "SCRIPT_NAME", r->uri);
377     }
378     else {
379         int path_info_start = ap_find_path_info(r->uri, r->path_info);
380
381         apr_table_setn(e, "SCRIPT_NAME",
382                       apr_pstrndup(r->pool, r->uri, path_info_start));
383
384         apr_table_setn(e, "PATH_INFO", r->path_info);
385     }
386
387     if (r->path_info && r->path_info[0]) {
388         /*
389          * To get PATH_TRANSLATED, treat PATH_INFO as a URI path.
390          * Need to re-escape it for this, since the entire URI was
391          * un-escaped before we determined where the PATH_INFO began.
392          */
393         request_rec *pa_req;
394
395         pa_req = ap_sub_req_lookup_uri(ap_escape_uri(r->pool, r->path_info), r,
396                                        NULL);
397
398         if (pa_req->filename) {
399             char *pt = apr_pstrcat(r->pool, pa_req->filename, pa_req->path_info,
400                                   NULL);
401 #ifdef WIN32
402             /* We need to make this a real Windows path name */
403             apr_filepath_merge(&pt, "", pt, APR_FILEPATH_NATIVE, r->pool);
404 #endif
405             apr_table_setn(e, "PATH_TRANSLATED", pt);
406         }
407         ap_destroy_sub_req(pa_req);
408     }
409 }
410
411
412 static int set_cookie_doo_doo(void *v, const char *key, const char *val)
413 {
414     apr_table_addn(v, key, val);
415     return 1;
416 }
417
418 AP_DECLARE(int) ap_scan_script_header_err_core(request_rec *r, char *buffer,
419                                        int (*getsfunc) (char *, int, void *),
420                                        void *getsfunc_data)
421 {
422     char x[MAX_STRING_LEN];
423     char *w, *l;
424     int p;
425     int cgi_status = HTTP_OK;
426     apr_table_t *merge;
427     apr_table_t *cookie_table;
428
429     if (buffer) {
430         *buffer = '\0';
431     }
432     w = buffer ? buffer : x;
433
434     /* temporary place to hold headers to merge in later */
435     merge = apr_table_make(r->pool, 10);
436
437     /* The HTTP specification says that it is legal to merge duplicate
438      * headers into one.  Some browsers that support Cookies don't like
439      * merged headers and prefer that each Set-Cookie header is sent
440      * separately.  Lets humour those browsers by not merging.
441      * Oh what a pain it is.
442      */
443     cookie_table = apr_table_make(r->pool, 2);
444     apr_table_do(set_cookie_doo_doo, cookie_table, r->err_headers_out, "Set-Cookie", NULL);
445
446     while (1) {
447
448         if ((*getsfunc) (w, MAX_STRING_LEN - 1, getsfunc_data) == 0) {
449             ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
450                           "Premature end of script headers: %s", r->filename);
451             return HTTP_INTERNAL_SERVER_ERROR;
452         }
453
454         /* Delete terminal (CR?)LF */
455
456         p = strlen(w);
457              /* Indeed, the host's '\n':
458                 '\012' for UNIX; '\015' for MacOS; '\025' for OS/390
459                  -- whatever the script generates.
460              */                                  
461         if (p > 0 && w[p - 1] == '\n') {
462             if (p > 1 && w[p - 2] == CR) {
463                 w[p - 2] = '\0';
464             }
465             else {
466                 w[p - 1] = '\0';
467             }
468         }
469
470         /*
471          * If we've finished reading the headers, check to make sure any
472          * HTTP/1.1 conditions are met.  If so, we're done; normal processing
473          * will handle the script's output.  If not, just return the error.
474          * The appropriate thing to do would be to send the script process a
475          * SIGPIPE to let it know we're ignoring it, close the channel to the
476          * script process, and *then* return the failed-to-meet-condition
477          * error.  Otherwise we'd be waiting for the script to finish
478          * blithering before telling the client the output was no good.
479          * However, we don't have the information to do that, so we have to
480          * leave it to an upper layer.
481          */
482         if (w[0] == '\0') {
483             int cond_status = OK;
484
485             if ((cgi_status == HTTP_OK) && (r->method_number == M_GET)) {
486                 cond_status = ap_meets_conditions(r);
487             }
488             apr_table_overlap(r->err_headers_out, merge,
489                 APR_OVERLAP_TABLES_MERGE);
490             if (!apr_is_empty_table(cookie_table)) {
491                 /* the cookies have already been copied to the cookie_table */
492                 apr_table_unset(r->err_headers_out, "Set-Cookie");
493                 r->err_headers_out = apr_table_overlay(r->pool,
494                     r->err_headers_out, cookie_table);
495             }
496             return cond_status;
497         }
498
499         /* if we see a bogus header don't ignore it. Shout and scream */
500
501 #if APR_CHARSET_EBCDIC
502             /* Chances are that we received an ASCII header text instead of
503              * the expected EBCDIC header lines. Try to auto-detect:
504              */
505         if (!(l = strchr(w, ':'))) {
506             int maybeASCII = 0, maybeEBCDIC = 0;
507             unsigned char *cp, native;
508             apr_size_t inbytes_left, outbytes_left;
509
510             for (cp = w; *cp != '\0'; ++cp) {
511                 native = apr_xlate_conv_byte(ap_hdrs_from_ascii, *cp);
512                 if (isprint(*cp) && !isprint(native))
513                     ++maybeEBCDIC;
514                 if (!isprint(*cp) && isprint(native))
515                     ++maybeASCII;
516             }
517             if (maybeASCII > maybeEBCDIC) {
518                 ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r->server,
519                              "CGI Interface Error: Script headers apparently ASCII: (CGI = %s)",
520                              r->filename);
521                 inbytes_left = outbytes_left = cp - w;
522                 apr_xlate_conv_buffer(ap_hdrs_from_ascii,
523                                       w, &inbytes_left, w, &outbytes_left);
524             }
525         }
526 #endif /*APR_CHARSET_EBCDIC*/
527         if (!(l = strchr(w, ':'))) {
528             char malformed[(sizeof MALFORMED_MESSAGE) + 1
529                            + MALFORMED_HEADER_LENGTH_TO_SHOW];
530
531             strcpy(malformed, MALFORMED_MESSAGE);
532             strncat(malformed, w, MALFORMED_HEADER_LENGTH_TO_SHOW);
533
534             if (!buffer) {
535                 /* Soak up all the script output - may save an outright kill */
536                 while ((*getsfunc) (w, MAX_STRING_LEN - 1, getsfunc_data)) {
537                     continue;
538                 }
539             }
540
541             ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
542                           "%s: %s", malformed, r->filename);
543             return HTTP_INTERNAL_SERVER_ERROR;
544         }
545
546         *l++ = '\0';
547         while (*l && apr_isspace(*l)) {
548             ++l;
549         }
550
551         if (!strcasecmp(w, "Content-type")) {
552             char *tmp;
553
554             /* Nuke trailing whitespace */
555
556             char *endp = l + strlen(l) - 1;
557             while (endp > l && apr_isspace(*endp)) {
558                 *endp-- = '\0';
559             }
560
561             tmp = apr_pstrdup(r->pool, l);
562             ap_content_type_tolower(tmp);
563             r->content_type = tmp;
564         }
565         /*
566          * If the script returned a specific status, that's what
567          * we'll use - otherwise we assume 200 OK.
568          */
569         else if (!strcasecmp(w, "Status")) {
570             r->status = cgi_status = atoi(l);
571             r->status_line = apr_pstrdup(r->pool, l);
572         }
573         else if (!strcasecmp(w, "Location")) {
574             apr_table_set(r->headers_out, w, l);
575         }
576         else if (!strcasecmp(w, "Content-Length")) {
577             apr_table_set(r->headers_out, w, l);
578         }
579         else if (!strcasecmp(w, "Transfer-Encoding")) {
580             apr_table_set(r->headers_out, w, l);
581         }
582         /*
583          * If the script gave us a Last-Modified header, we can't just
584          * pass it on blindly because of restrictions on future values.
585          */
586         else if (!strcasecmp(w, "Last-Modified")) {
587             ap_update_mtime(r, apr_date_parse_http(l));
588             ap_set_last_modified(r);
589         }
590         else if (!strcasecmp(w, "Set-Cookie")) {
591             apr_table_add(cookie_table, w, l);
592         }
593         else {
594             apr_table_add(merge, w, l);
595         }
596     }
597
598     return OK;
599 }
600
601 static int getsfunc_FILE(char *buf, int len, void *f)
602 {
603     return apr_file_gets(buf, len, (apr_file_t *) f) == APR_SUCCESS;
604 }
605
606 AP_DECLARE(int) ap_scan_script_header_err(request_rec *r, apr_file_t *f,
607                                           char *buffer)
608 {
609     return ap_scan_script_header_err_core(r, buffer, getsfunc_FILE, f);
610 }
611
612 struct vastrs {
613     va_list args;
614     int arg;
615     const char *curpos;
616 };
617
618 static int getsfunc_STRING(char *w, int len, void *pvastrs)
619 {
620     struct vastrs *strs = (struct vastrs*) pvastrs;
621     const char *p;
622     int t;
623     
624     if (!strs->curpos || !*strs->curpos) 
625         return 0;
626     p = ap_strchr_c(strs->curpos, '\n');
627     if (p)
628         ++p;
629     else
630         p = ap_strchr_c(strs->curpos, '\0');
631     t = p - strs->curpos;
632     if (t > len)
633         t = len;
634     strncpy (w, strs->curpos, t);
635     w[t] = '\0';
636     if (!strs->curpos[t]) {
637         ++strs->arg;
638         strs->curpos = va_arg(strs->args, const char *);
639     }
640     else
641         strs->curpos += t;
642     return t;    
643 }
644
645 /* ap_scan_script_header_err_strs() accepts additional const char* args...
646  * each is treated as one or more header lines, and the first non-header
647  * character is returned to **arg, **data.  (The first optional arg is
648  * counted as 0.)
649  */
650 AP_DECLARE_NONSTD(int) ap_scan_script_header_err_strs(request_rec *r, 
651                                                       char *buffer, 
652                                                       const char **termch,
653                                                       int *termarg, ...)
654 {
655     struct vastrs strs;
656     int res;
657
658     va_start(strs.args, termarg);
659     strs.arg = 0;
660     strs.curpos = va_arg(strs.args, char*);
661     res = ap_scan_script_header_err_core(r, buffer, getsfunc_STRING, (void *) &strs);
662     if (termch)
663         *termch = strs.curpos;
664     if (termarg)
665         *termarg = strs.arg;
666     va_end(strs.args);
667     return res;
668 }