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