2 * $Id: fcgi_config.c,v 1.28 2001/05/03 20:51:24 robs Exp $
8 #pragma warning( disable : 4100 4706 )
11 /*******************************************************************************
12 * Get the next configuration directive argument, & return an in_addr and port.
13 * The arg must be in the form "host:port" where host can be an IP or hostname.
14 * The pool arg should be persistant storage.
16 static const char *get_host_n_port(pool
*p
, const char **arg
,
17 const char **host
, u_short
*port
)
19 char *cvptr
, *portStr
;
22 *host
= ap_getword_conf(p
, arg
);
26 portStr
= strchr(*host
, ':');
28 return "missing port specification";
30 /* Split the host and port portions */
33 /* Convert port number */
34 tmp
= (u_short
) strtol(portStr
, &cvptr
, 10);
35 if (*cvptr
!= '\0' || tmp
< 1 || tmp
> USHRT_MAX
)
36 return ap_pstrcat(p
, "bad port number \"", portStr
, "\"", NULL
);
38 *port
= (unsigned short) tmp
;
43 /*******************************************************************************
44 * Get the next configuration directive argument, & return an u_short.
45 * The pool arg should be temporary storage.
47 static const char *get_u_short(pool
*p
, const char **arg
,
48 u_short
*num
, u_short min
)
52 const char *txt
= ap_getword_conf(p
, arg
);
58 tmp
= strtol(txt
, &ptr
, 10);
61 return ap_pstrcat(p
, "\"", txt
, "\" must be a positive integer", NULL
);
64 if (tmp
< min
|| tmp
> USHRT_MAX
) {
65 return ap_psprintf(p
, "\"%u\" must be >= %u and < %u", *num
, min
, USHRT_MAX
);
73 static const char *get_int(pool
*p
, const char **arg
, int *num
, int min
)
76 const char *val
= ap_getword_conf(p
, arg
);
83 *num
= (int) strtol(val
, &cp
, 10);
87 return ap_pstrcat(p
, "can't parse ", "\"", val
, "\"", NULL
);
91 return ap_psprintf(p
, "\"%d\" must be >= %d", *num
, min
);
97 /*******************************************************************************
98 * Get the next configuration directive argument, & return an u_int.
99 * The pool arg should be temporary storage.
101 static const char *get_u_int(pool
*p
, const char **arg
,
102 u_int
*num
, u_int min
)
105 const char *val
= ap_getword_conf(p
, arg
);
109 *num
= (u_int
)strtol(val
, &ptr
, 10);
112 return ap_pstrcat(p
, "\"", val
, "\" must be a positive integer", NULL
);
114 return ap_psprintf(p
, "\"%u\" must be >= %u", *num
, min
);
118 /*******************************************************************************
119 * Get the next configuration directive argument, & return a float.
120 * The pool arg should be temporary storage.
122 static const char *get_float(pool
*p
, const char **arg
,
123 float *num
, float min
, float max
)
126 const char *val
= ap_getword_conf(p
, arg
);
130 *num
= (float) strtod(val
, &ptr
);
133 return ap_pstrcat(p
, "\"", val
, "\" is not a floating point number", NULL
);
134 if (*num
< min
|| *num
> max
)
135 return ap_psprintf(p
, "\"%f\" is not between %f and %f", *num
, min
, max
);
139 const char *fcgi_config_set_env_var(pool
*p
, char **envp
, unsigned int *envc
, char * var
)
141 if (*envc
>= MAX_INIT_ENV_VARS
) {
142 return "too many variables, must be <= MAX_INIT_ENV_VARS";
145 if (strchr(var
, '=') == NULL
) {
146 *(envp
+ *envc
) = ap_pstrcat(p
, var
, "=", getenv(var
), NULL
);
149 *(envp
+ *envc
) = var
;
157 /*******************************************************************************
158 * Get the next configuration directive argument, & add it to an env array.
159 * The pool arg should be permanent storage.
161 static const char *get_env_var(pool
*p
, const char **arg
, char **envp
, unsigned int *envc
)
163 char * const val
= ap_getword_conf(p
, arg
);
169 return fcgi_config_set_env_var(p
, envp
, envc
, val
);
172 static const char *get_pass_header(pool
*p
, const char **arg
, array_header
**array
)
177 *array
= ap_make_array(p
, 10, sizeof(char*));
180 header
= (const char **)ap_push_array(*array
);
181 *header
= ap_getword_conf(p
, arg
);
183 return header
? NULL
: "\"\"";
186 /*******************************************************************************
187 * Return a "standard" message for common configuration errors.
189 static const char *invalid_value(pool
*p
, const char *cmd
, const char *id
,
190 const char *opt
, const char *err
)
192 return ap_psprintf(p
, "%s%s%s: invalid value for %s: %s",
193 cmd
, id
? " " : "", id
? id
: "", opt
, err
);
196 /*******************************************************************************
197 * Set/Reset the uid/gid that Apache and the PM will run as. This is ap_user_id
198 * and ap_group_id if we're started as root, and euid/egid otherwise. Also try
199 * to check that the config files don't set the User/Group after a FastCGI
200 * directive is used that depends on it.
202 /*@@@ To be complete, we should save a handle to the server each AppClass is
203 * configured in and at init() check that the user/group is still what we
204 * thought it was. Also the other directives should only be allowed in the
205 * parent Apache server.
207 const char *fcgi_config_set_fcgi_uid_n_gid(int set
)
209 static int isSet
= 0;
211 uid_t uid
= geteuid();
212 gid_t gid
= getegid();
216 fcgi_user_id
= (uid_t
)-1;
217 fcgi_group_id
= (gid_t
)-1;
221 uid
= uid
? uid
: ap_user_id
;
222 gid
= gid
? gid
: ap_group_id
;
224 if (isSet
&& (uid
!= fcgi_user_id
|| gid
!= fcgi_group_id
)) {
225 return "User/Group commands must preceed FastCGI server definitions";
235 void fcgi_config_reset_globals(void* dummy
)
237 fcgi_config_pool
= NULL
;
239 fcgi_config_set_fcgi_uid_n_gid(0);
241 fcgi_socket_dir
= DEFAULT_SOCK_DIR
;
243 fcgi_dynamic_total_proc_count
= 0;
244 fcgi_dynamic_epoch
= 0;
245 fcgi_dynamic_last_analyzed
= 0;
247 dynamicMaxProcs
= FCGI_DEFAULT_MAX_PROCS
;
248 dynamicMinProcs
= FCGI_DEFAULT_MIN_PROCS
;
249 dynamicMaxClassProcs
= FCGI_DEFAULT_MAX_CLASS_PROCS
;
250 dynamicKillInterval
= FCGI_DEFAULT_KILL_INTERVAL
;
251 dynamicUpdateInterval
= FCGI_DEFAULT_UPDATE_INTERVAL
;
252 dynamicGain
= FCGI_DEFAULT_GAIN
;
253 dynamicThreshold1
= FCGI_DEFAULT_THRESHOLD_1
;
254 dynamicThresholdN
= FCGI_DEFAULT_THRESHOLD_N
;
255 dynamicPleaseStartDelay
= FCGI_DEFAULT_START_PROCESS_DELAY
;
256 dynamicAppConnectTimeout
= FCGI_DEFAULT_APP_CONN_TIMEOUT
;
257 dynamicEnvp
= &fcgi_empty_env
;
258 dynamicProcessSlack
= FCGI_DEFAULT_PROCESS_SLACK
;
259 dynamicAutoRestart
= FCGI_DEFAULT_RESTART_DYNAMIC
;
260 dynamicAutoUpdate
= FCGI_DEFAULT_AUTOUPDATE
;
261 dynamicListenQueueDepth
= FCGI_DEFAULT_LISTEN_Q
;
262 dynamicInitStartDelay
= DEFAULT_INIT_START_DELAY
;
263 dynamicRestartDelay
= FCGI_DEFAULT_RESTART_DELAY
;
264 dynamic_pass_headers
= NULL
;
265 dynamic_idle_timeout
= FCGI_DEFAULT_IDLE_TIMEOUT
;
268 /* Close any old pipe (HUP/USR1) */
269 if (fcgi_pm_pipe
[0] != -1) {
270 close(fcgi_pm_pipe
[0]);
271 fcgi_pm_pipe
[0] = -1;
273 if (fcgi_pm_pipe
[1] != -1) {
274 close(fcgi_pm_pipe
[1]);
275 fcgi_pm_pipe
[1] = -1;
280 /*******************************************************************************
281 * Create a directory to hold Unix/Domain sockets.
283 const char *fcgi_config_make_dir(pool
*tp
, char *path
)
286 const char *err
= NULL
;
288 /* Is the directory spec'd correctly */
290 return "path is not absolute (it must start with a \"/\")";
293 int i
= strlen(path
) - 1;
295 /* Strip trailing "/"s */
296 while(i
> 0 && path
[i
] == '/') path
[i
--] = '\0';
300 if (stat(path
, &finfo
) != 0) {
301 /* No, but maybe we can create it */
303 if (mkdir(path
) != 0)
305 if (mkdir(path
, S_IRWXU
) != 0)
308 return ap_psprintf(tp
,
309 "doesn't exist and can't be created: %s",
314 /* If we're root, we're gonna setuid/setgid so we need to chown */
315 if (geteuid() == 0 && chown(path
, ap_user_id
, ap_group_id
) != 0) {
316 return ap_psprintf(tp
,
317 "can't chown() to the server (uid %ld, gid %ld): %s",
318 (long)ap_user_id
, (long)ap_group_id
, strerror(errno
));
323 /* Yes, is it a directory? */
324 if (!S_ISDIR(finfo
.st_mode
))
325 return "isn't a directory!";
327 /* Can we RWX in there? */
329 err
= fcgi_util_check_access(tp
, NULL
, &finfo
, _S_IREAD
| _S_IWRITE
| _S_IEXEC
, fcgi_user_id
, fcgi_group_id
);
331 err
= fcgi_util_check_access(tp
, NULL
, &finfo
, R_OK
| W_OK
| X_OK
,
332 fcgi_user_id
, fcgi_group_id
);
335 return ap_psprintf(tp
,
336 "access for server (uid %ld, gid %ld) failed: %s",
337 (long)fcgi_user_id
, (long)fcgi_group_id
, err
);
343 /*******************************************************************************
344 * Create a "dynamic" subdirectory. If the directory
345 * already exists we don't mess with it unless 'wax' is set.
347 const char *fcgi_config_make_dynamic_dir(pool
*p
, const int wax
)
351 struct dirent
*dirp
= NULL
;
355 fcgi_dynamic_dir
= ap_pstrcat(p
, fcgi_socket_dir
, "/dynamic", NULL
);
357 if ((err
= fcgi_config_make_dir(p
, fcgi_dynamic_dir
)))
358 return ap_psprintf(p
, "can't create dynamic directory \"%s\": %s", fcgi_dynamic_dir
, err
);
360 /* Don't step on a running server unless its OK. */
364 /* Create a subpool for the directory operations */
365 tp
= ap_make_sub_pool(p
);
367 dp
= ap_popendir(tp
, fcgi_dynamic_dir
);
370 return ap_psprintf(p
, "can't open dynamic directory \"%s\": %s",
371 fcgi_dynamic_dir
, strerror(errno
));
374 /* Delete everything in the directory, its all FCGI specific */
375 while ((dirp
= readdir(dp
)) != NULL
) {
376 if (strcmp(dirp
->d_name
, ".") == 0
377 || strcmp(dirp
->d_name
, "..") == 0) {
381 unlink(ap_pstrcat(tp
, fcgi_dynamic_dir
, "/", dirp
->d_name
, NULL
));
387 fcgi_dynamic_dir
= ap_pstrcat(p
, fcgi_socket_dir
, "dynamic", NULL
);
393 /*******************************************************************************
394 * Change the directory used for the Unix/Domain sockets from the default.
395 * Create the directory and the "dynamic" subdirectory.
397 const char *fcgi_config_set_socket_dir(cmd_parms
*cmd
, void *dummy
, char *arg
)
399 pool
* const tp
= cmd
->temp_pool
;
400 const char * const name
= cmd
->cmd
->name
;
403 if (strcmp(fcgi_socket_dir
, DEFAULT_SOCK_DIR
) != 0) {
404 return ap_psprintf(tp
, "%s %s: already defined as \"%s\"",
405 name
, arg
, fcgi_socket_dir
);
408 err
= fcgi_config_set_fcgi_uid_n_gid(1);
410 return ap_psprintf(tp
, "%s %s: %s", name
, arg
, err
);
412 if (fcgi_servers
!= NULL
) {
413 return ap_psprintf(tp
,
414 "The %s command must preceed static FastCGI server definitions",
419 arg
= ap_os_canonical_filename(cmd
->pool
, arg
);
420 arg
= ap_server_root_relative(cmd
->pool
, arg
);
422 if (strncmp(arg
, "\\\\.\\pipe\\", 9) != 0)
423 return ap_psprintf(tp
, "%s %s is invalid format",name
, arg
);
426 fcgi_socket_dir
= arg
;
429 err
= fcgi_config_make_dir(tp
, fcgi_socket_dir
);
431 return ap_psprintf(tp
, "%s %s: %s", name
, arg
, err
);
433 err
= fcgi_config_make_dynamic_dir(cmd
->pool
, 0);
435 return ap_psprintf(tp
, "%s %s: %s", name
, arg
, err
);
441 /*******************************************************************************
442 * Enable, disable, or specify the path to a wrapper used to invoke all
443 * FastCGI applications.
445 const char *fcgi_config_set_wrapper(cmd_parms
*cmd
, void *dummy
, const char *arg
)
447 const char *err
= NULL
;
448 const char * const name
= cmd
->cmd
->name
;
449 pool
* const tp
= cmd
->temp_pool
;
452 if (!ap_suexec_enabled
&& strcasecmp(arg
, "On") == 0) {
453 fprintf(stderr
, "Warning: \"%s On\" requires SUEXEC be enabled in Apache", name
);
457 err
= fcgi_config_set_fcgi_uid_n_gid(1);
459 return ap_psprintf(tp
, "%s %s: %s", name
, arg
, err
);
461 if (fcgi_servers
!= NULL
) {
462 return ap_psprintf(tp
,
463 "The %s command must preceed static FastCGI server definitions", name
);
466 if (strcasecmp(arg
, "On") == 0) {
467 fcgi_wrapper
= SUEXEC_BIN
;
469 else if (strcasecmp(arg
, "Off") == 0) {
473 wrapper
= (char *) ap_os_canonical_filename(cmd
->pool
, arg
);
474 wrapper
= ap_server_root_relative(cmd
->pool
, wrapper
);
477 err
= fcgi_util_check_access(tp
, wrapper
, NULL
, _S_IEXEC
, fcgi_user_id
, fcgi_group_id
);
479 err
= fcgi_util_check_access(tp
, wrapper
, NULL
, X_OK
, fcgi_user_id
, fcgi_group_id
);
483 return ap_psprintf(tp
,
484 "%s: \"%s\" access for server (uid %ld, gid %ld) failed: %s",
485 name
, wrapper
, (long)fcgi_user_id
, (long)fcgi_group_id
, err
);
488 fcgi_wrapper
= wrapper
;
493 /*******************************************************************************
494 * Configure a static FastCGI server.
496 const char *fcgi_config_new_static_server(cmd_parms
*cmd
, void *dummy
, const char *arg
)
499 pool
*p
= cmd
->pool
, *tp
= cmd
->temp_pool
;
500 const char *name
= cmd
->cmd
->name
;
501 char *fs_path
= ap_getword_conf(p
, &arg
);
502 const char *option
, *err
;
504 /* Allocate temp storage for the array of initial environment variables */
505 char **envp
= ap_pcalloc(tp
, sizeof(char *) * (MAX_INIT_ENV_VARS
+ 3));
506 unsigned int envc
= 0;
509 HANDLE mutex
= ap_create_mutex(NULL
);
511 SetHandleInformation(mutex
, HANDLE_FLAG_INHERIT
, TRUE
);
514 if (*fs_path
== '\0')
515 return "AppClass requires a pathname!?";
517 if ((err
= fcgi_config_set_fcgi_uid_n_gid(1)) != NULL
)
518 return ap_psprintf(tp
, "%s %s: %s", name
, fs_path
, err
);
520 fs_path
= ap_os_canonical_filename(p
, fs_path
);
521 fs_path
= ap_server_root_relative(p
, fs_path
);
523 ap_getparents(fs_path
);
524 ap_no2slash(fs_path
);
526 /* See if we've already got one of these configured */
527 s
= fcgi_util_fs_get_by_id(fs_path
, cmd
->server
->server_uid
,
528 cmd
->server
->server_gid
);
531 return ap_psprintf(tp
,
532 "%s: redefinition of a previously defined FastCGI server \"%s\" with uid=%ld and gid=%ld",
533 name
, fs_path
, (long)cmd
->server
->server_uid
,
534 (long)cmd
->server
->server_gid
);
537 return ap_psprintf(tp
,
538 "%s: redefinition of a previously defined FastCGI server \"%s\"",
543 err
= fcgi_util_fs_is_path_ok(tp
, fs_path
, NULL
);
545 return ap_psprintf(tp
, "%s: \"%s\" %s", name
, fs_path
, err
);
548 s
= fcgi_util_fs_new(p
);
549 s
->fs_path
= fs_path
;
550 s
->directive
= APP_CLASS_STANDARD
;
551 s
->restartOnExit
= TRUE
;
555 // TCP FastCGI applications require SystemRoot be present in the environment
556 // Put it in both for consistency to the application
557 fcgi_config_set_env_var(tp
, envp
, &envc
, "SystemRoot");
559 s
->mutex_env_string
= ap_psprintf(p
, "_FCGI_MUTEX_=%ld", mutex
);;
565 s
->uid
= cmd
->server
->server_uid
;
566 pw
= getpwuid(s
->uid
);
568 return ap_psprintf(tp
, "mod_fastcgi: "
569 "getpwuid() couldn't determine the username for uid '%ld', "
570 "you probably need to modify the User directive: %s",
571 (long)s
->uid
, strerror(errno
));
573 s
->user
= ap_pstrdup(p
, pw
->pw_name
);
574 s
->username
= s
->user
;
576 s
->gid
= cmd
->server
->server_gid
;
577 gr
= getgrgid(s
->gid
);
579 return ap_psprintf(tp
, "mod_fastcgi: "
580 "getgrgid() couldn't determine the group name for gid '%ld', "
581 "you probably need to modify the Group directive: %s\n",
582 (long)s
->gid
, strerror(errno
));
584 s
->group
= ap_pstrdup(p
, gr
->gr_name
);
588 /* Parse directive arguments */
590 option
= ap_getword_conf(tp
, &arg
);
592 if (strcasecmp(option
, "-processes") == 0) {
593 if ((err
= get_u_int(tp
, &arg
, &s
->numProcesses
, 1)))
594 return invalid_value(tp
, name
, fs_path
, option
, err
);
596 else if (strcasecmp(option
, "-restart-delay") == 0) {
597 if ((err
= get_u_int(tp
, &arg
, &s
->restartDelay
, 0)))
598 return invalid_value(tp
, name
, fs_path
, option
, err
);
600 else if (strcasecmp(option
, "-init-start-delay") == 0) {
601 if ((err
= get_int(tp
, &arg
, &s
->initStartDelay
, 0)))
602 return invalid_value(tp
, name
, fs_path
, option
, err
);
604 else if (strcasecmp(option
, "-priority") == 0) {
605 if ((err
= get_u_int(tp
, &arg
, &s
->processPriority
, 0)))
606 return invalid_value(tp
, name
, fs_path
, option
, err
);
608 else if (strcasecmp(option
, "-listen-queue-depth") == 0) {
609 if ((err
= get_u_int(tp
, &arg
, &s
->listenQueueDepth
, 1)))
610 return invalid_value(tp
, name
, fs_path
, option
, err
);
612 else if (strcasecmp(option
, "-appConnTimeout") == 0) {
613 if ((err
= get_u_int(tp
, &arg
, &s
->appConnectTimeout
, 0)))
614 return invalid_value(tp
, name
, fs_path
, option
, err
);
616 else if (strcasecmp(option
, "-idle-timeout") == 0) {
617 if ((err
= get_u_int(tp
, &arg
, &s
->idle_timeout
, 1)))
618 return invalid_value(tp
, name
, fs_path
, option
, err
);
620 else if (strcasecmp(option
, "-port") == 0) {
621 if ((err
= get_u_short(tp
, &arg
, &s
->port
, 1)))
622 return invalid_value(tp
, name
, fs_path
, option
, err
);
624 else if (strcasecmp(option
, "-socket") == 0) {
625 s
->socket_path
= ap_getword_conf(tp
, &arg
);
626 if (*s
->socket_path
== '\0')
627 return invalid_value(tp
, name
, fs_path
, option
, "\"\"");
629 else if (strcasecmp(option
, "-initial-env") == 0) {
630 if ((err
= get_env_var(p
, &arg
, envp
, &envc
)))
631 return invalid_value(tp
, name
, fs_path
, option
, err
);
633 else if (strcasecmp(option
, "-pass-header") == 0) {
634 if ((err
= get_pass_header(p
, &arg
, &s
->pass_headers
)))
635 return invalid_value(tp
, name
, fs_path
, option
, err
);
637 else if (strcasecmp(option
, "-flush") == 0) {
641 return ap_psprintf(tp
, "%s %s: invalid option: %s", name
, fs_path
, option
);
645 if (s
->socket_path
!= NULL
&& s
->port
!= 0) {
646 return ap_psprintf(tp
,
647 "%s %s: -port and -socket are mutually exclusive options",
651 /* Move env array to a surviving pool */
653 s
->envp
= (char **)ap_palloc(p
, sizeof(char *) * ++envc
);
654 memcpy(s
->envp
, envp
, sizeof(char *) * envc
);
656 /* Initialize process structs */
657 s
->procs
= fcgi_util_fs_create_procs(p
, s
->numProcesses
);
659 /* Build the appropriate sockaddr structure */
661 err
= fcgi_util_socket_make_inet_addr(p
, (struct sockaddr_in
**)&s
->socket_addr
,
662 &s
->socket_addr_len
, NULL
, s
->port
);
664 return ap_psprintf(tp
, "%s %s: %s", name
, fs_path
, err
);
666 err
= fcgi_util_socket_make_inet_addr(p
, (struct sockaddr_in
**)&s
->dest_addr
,
667 &s
->socket_addr_len
, "localhost", s
->port
);
669 return ap_psprintf(tp
, "%s %s: %s", name
, fs_path
, err
);
672 if (s
->socket_path
== NULL
)
673 s
->socket_path
= fcgi_util_socket_hash_filename(tp
, fs_path
, s
->user
, s
->group
);
674 s
->socket_path
= fcgi_util_socket_make_path_absolute(p
, s
->socket_path
, 0);
676 err
= fcgi_util_socket_make_domain_addr(p
, (struct sockaddr_un
**)&s
->socket_addr
,
677 &s
->socket_addr_len
, s
->socket_path
);
679 return ap_psprintf(tp
, "%s %s: %s", name
, fs_path
, err
);
683 /* Add it to the list of FastCGI servers */
689 /*******************************************************************************
690 * Configure a static FastCGI server that is started/managed elsewhere.
692 const char *fcgi_config_new_external_server(cmd_parms
*cmd
, void *dummy
, const char *arg
)
695 pool
* const p
= cmd
->pool
, *tp
= cmd
->temp_pool
;
696 const char * const name
= cmd
->cmd
->name
;
697 char *fs_path
= ap_getword_conf(p
, &arg
);
698 const char *option
, *err
;
701 return ap_pstrcat(tp
, name
, " requires a path and either a -socket or -host option", NULL
);
704 fs_path
= ap_os_canonical_filename(p
, fs_path
);
705 fs_path
= ap_server_root_relative(p
, fs_path
);
707 ap_getparents(fs_path
);
708 ap_no2slash(fs_path
);
710 /* See if we've already got one of these bettys configured */
711 s
= fcgi_util_fs_get_by_id(fs_path
, cmd
->server
->server_uid
,
712 cmd
->server
->server_gid
);
715 return ap_psprintf(tp
,
716 "%s: redefinition of a previously defined class \"%s\" with uid=%ld and gid=%ld",
717 name
, fs_path
, (long)cmd
->server
->server_uid
,
718 (long)cmd
->server
->server_gid
);
721 return ap_psprintf(tp
,
722 "%s: redefinition of previously defined class \"%s\"", name
, fs_path
);
726 s
= fcgi_util_fs_new(p
);
727 s
->fs_path
= fs_path
;
728 s
->directive
= APP_CLASS_EXTERNAL
;
730 err
= fcgi_util_fs_set_uid_n_gid(p
, s
, cmd
->server
->server_uid
, cmd
->server
->server_gid
);
732 return ap_psprintf(tp
, "%s %s: %s", name
, fs_path
, err
);
734 /* Parse directive arguments */
735 while (*arg
!= '\0') {
736 option
= ap_getword_conf(tp
, &arg
);
738 if (strcasecmp(option
, "-host") == 0) {
739 if ((err
= get_host_n_port(p
, &arg
, &s
->host
, &s
->port
)))
740 return invalid_value(tp
, name
, fs_path
, option
, err
);
742 else if (strcasecmp(option
, "-socket") == 0) {
743 s
->socket_path
= ap_getword_conf(tp
, &arg
);
744 if (*s
->socket_path
== '\0')
745 return invalid_value(tp
, name
, fs_path
, option
, "\"\"");
747 else if (strcasecmp(option
, "-appConnTimeout") == 0) {
748 if ((err
= get_u_int(tp
, &arg
, &s
->appConnectTimeout
, 0)))
749 return invalid_value(tp
, name
, fs_path
, option
, err
);
751 else if (strcasecmp(option
, "-idle-timeout") == 0) {
752 if ((err
= get_u_int(tp
, &arg
, &s
->idle_timeout
, 1)))
753 return invalid_value(tp
, name
, fs_path
, option
, err
);
755 else if (strcasecmp(option
, "-pass-header") == 0) {
756 if ((err
= get_pass_header(p
, &arg
, &s
->pass_headers
)))
757 return invalid_value(tp
, name
, fs_path
, option
, err
);
759 else if (strcasecmp(option
, "-flush") == 0) {
763 return ap_psprintf(tp
, "%s %s: invalid option: %s", name
, fs_path
, option
);
767 /* Require one of -socket or -host, but not both */
768 if (s
->socket_path
!= NULL
&& s
->port
!= 0) {
769 return ap_psprintf(tp
,
770 "%s %s: -host and -socket are mutually exclusive options",
773 if (s
->socket_path
== NULL
&& s
->port
== 0) {
774 return ap_psprintf(tp
,
775 "%s %s: -socket or -host option missing", name
, fs_path
);
778 /* Build the appropriate sockaddr structure */
780 err
= fcgi_util_socket_make_inet_addr(p
, (struct sockaddr_in
**)&s
->socket_addr
,
781 &s
->socket_addr_len
, s
->host
, s
->port
);
783 return ap_psprintf(tp
, "%s %s: %s", name
, fs_path
, err
);
785 s
->socket_path
= fcgi_util_socket_make_path_absolute(p
, s
->socket_path
, 0);
787 err
= fcgi_util_socket_make_domain_addr(p
, (struct sockaddr_un
**)&s
->socket_addr
,
788 &s
->socket_addr_len
, s
->socket_path
);
790 return ap_psprintf(tp
, "%s %s: %s", name
, fs_path
, err
);
794 /* Add it to the list of FastCGI servers */
801 *----------------------------------------------------------------------
803 * fcgi_config_set_config --
805 * Implements the FastCGI FCGIConfig configuration directive.
806 * This command adds routines to control the execution of the
807 * dynamic FastCGI processes.
810 *----------------------------------------------------------------------
812 const char *fcgi_config_set_config(cmd_parms
*cmd
, void *dummy
, const char *arg
)
814 pool
* const p
= cmd
->pool
;
815 pool
* const tp
= cmd
->temp_pool
;
816 const char *err
, *option
;
817 const char * const name
= cmd
->cmd
->name
;
819 /* Allocate temp storage for an initial environment */
820 unsigned int envc
= 0;
821 char **envp
= (char **)ap_pcalloc(tp
, sizeof(char *) * (MAX_INIT_ENV_VARS
+ 3));
823 /* Parse the directive arguments */
825 option
= ap_getword_conf(tp
, &arg
);
827 if (strcasecmp(option
, "-maxProcesses") == 0) {
828 if ((err
= get_u_int(tp
, &arg
, &dynamicMaxProcs
, 1)))
829 return invalid_value(tp
, name
, NULL
, option
, err
);
831 else if (strcasecmp(option
, "-minProcesses") == 0) {
832 if ((err
= get_int(tp
, &arg
, &dynamicMinProcs
, 0)))
833 return invalid_value(tp
, name
, NULL
, option
, err
);
835 else if (strcasecmp(option
, "-maxClassProcesses") == 0) {
836 if ((err
= get_int(tp
, &arg
, &dynamicMaxClassProcs
, 1)))
837 return invalid_value(tp
, name
, NULL
, option
, err
);
839 else if (strcasecmp(option
, "-killInterval") == 0) {
840 if ((err
= get_u_int(tp
, &arg
, &dynamicKillInterval
, 1)))
841 return invalid_value(tp
, name
, NULL
, option
, err
);
843 else if (strcasecmp(option
, "-updateInterval") == 0) {
844 if ((err
= get_u_int(tp
, &arg
, &dynamicUpdateInterval
, 1)))
845 return invalid_value(tp
, name
, NULL
, option
, err
);
847 else if (strcasecmp(option
, "-gainValue") == 0) {
848 if ((err
= get_float(tp
, &arg
, &dynamicGain
, 0.0, 1.0)))
849 return invalid_value(tp
, name
, NULL
, option
, err
);
851 else if ((strcasecmp(option
, "-singleThreshold") == 0)
852 || (strcasecmp(option
, "-singleThreshhold") == 0))
854 if ((err
= get_int(tp
, &arg
, &dynamicThreshold1
, 0)))
855 return invalid_value(tp
, name
, NULL
, option
, err
);
857 else if ((strcasecmp(option
, "-multiThreshold") == 0)
858 || (strcasecmp(option
, "-multiThreshhold") == 0))
860 if ((err
= get_int(tp
, &arg
, &dynamicThresholdN
, 0)))
861 return invalid_value(tp
, name
, NULL
, option
, err
);
863 else if (strcasecmp(option
, "-startDelay") == 0) {
864 if ((err
= get_u_int(tp
, &arg
, &dynamicPleaseStartDelay
, 1)))
865 return invalid_value(tp
, name
, NULL
, option
, err
);
867 else if (strcasecmp(option
, "-initial-env") == 0) {
868 if ((err
= get_env_var(p
, &arg
, envp
, &envc
)))
869 return invalid_value(tp
, name
, NULL
, option
, err
);
871 else if (strcasecmp(option
, "-pass-header") == 0) {
872 if ((err
= get_pass_header(p
, &arg
, &dynamic_pass_headers
)))
873 return invalid_value(tp
, name
, NULL
, option
, err
);
875 else if (strcasecmp(option
, "-appConnTimeout") == 0) {
876 if ((err
= get_u_int(tp
, &arg
, &dynamicAppConnectTimeout
, 0)))
877 return invalid_value(tp
, name
, NULL
, option
, err
);
879 else if (strcasecmp(option
, "-idle-timeout") == 0) {
880 if ((err
= get_u_int(tp
, &arg
, &dynamic_idle_timeout
, 1)))
881 return invalid_value(tp
, name
, NULL
, option
, err
);
883 else if (strcasecmp(option
, "-listen-queue-depth") == 0) {
884 if ((err
= get_u_int(tp
, &arg
, &dynamicListenQueueDepth
, 1)))
885 return invalid_value(tp
, name
, NULL
, option
, err
);
887 else if (strcasecmp(option
, "-restart-delay") == 0) {
888 if ((err
= get_u_int(tp
, &arg
, &dynamicRestartDelay
, 0)))
889 return invalid_value(tp
, name
, NULL
, option
, err
);
891 else if (strcasecmp(option
, "-init-start-delay") == 0) {
892 if ((err
= get_u_int(tp
, &arg
, &dynamicInitStartDelay
, 0)))
893 return invalid_value(tp
, name
, NULL
, option
, err
);
895 else if (strcasecmp(option
, "-processSlack") == 0) {
896 if ((err
= get_u_int(tp
, &arg
, &dynamicProcessSlack
, 1)))
897 return invalid_value(tp
, name
, NULL
, option
, err
);
899 else if (strcasecmp(option
, "-restart") == 0) {
900 dynamicAutoRestart
= 1;
902 else if (strcasecmp(option
, "-autoUpdate") == 0) {
903 dynamicAutoUpdate
= 1;
906 return ap_psprintf(tp
, "%s: invalid option: %s", name
, option
);
910 /* Move env array to a surviving pool, leave an extra slot for WIN32 _FCGI_MUTEX_ */
912 dynamicEnvp
= (char **)ap_palloc(p
, sizeof(char *) * ++envc
);
913 memcpy(dynamicEnvp
, envp
, sizeof(char *) * envc
);
918 void *fcgi_config_create_dir_config(pool
*p
, char *dummy
)
920 fcgi_dir_config
*dir_config
= ap_pcalloc(p
, sizeof(fcgi_dir_config
));
922 dir_config
->authenticator_options
= FCGI_AUTHORITATIVE
;
923 dir_config
->authorizer_options
= FCGI_AUTHORITATIVE
;
924 dir_config
->access_checker_options
= FCGI_AUTHORITATIVE
;
930 const char *fcgi_config_new_auth_server(cmd_parms
* const cmd
,
931 fcgi_dir_config
*dir_config
, const char *fs_path
, const char * const compat
)
933 pool
* const tp
= cmd
->temp_pool
;
934 const uid_t uid
= cmd
->server
->server_uid
;
935 const gid_t gid
= cmd
->server
->server_gid
;
938 auth_server
= (char *) ap_os_canonical_filename(cmd
->pool
, fs_path
);
939 auth_server
= ap_server_root_relative(cmd
->pool
, auth_server
);
941 /* Make sure its already configured or at least a candidate for dynamic */
942 if (fcgi_util_fs_get_by_id(auth_server
, uid
, gid
) == NULL
) {
943 const char *err
= fcgi_util_fs_is_path_ok(tp
, auth_server
, NULL
);
945 return ap_psprintf(tp
, "%s: \"%s\" %s", cmd
->cmd
->name
, auth_server
, err
);
948 if (compat
&& strcasecmp(compat
, "-compat"))
949 return ap_psprintf(cmd
->temp_pool
, "%s: unknown option: \"%s\"", cmd
->cmd
->name
, compat
);
951 switch((int)cmd
->info
) {
952 case FCGI_AUTH_TYPE_AUTHENTICATOR
:
953 dir_config
->authenticator
= auth_server
;
954 dir_config
->authenticator_options
|= (compat
) ? FCGI_COMPAT
: 0;
956 case FCGI_AUTH_TYPE_AUTHORIZER
:
957 dir_config
->authorizer
= auth_server
;
958 dir_config
->authorizer_options
|= (compat
) ? FCGI_COMPAT
: 0;
960 case FCGI_AUTH_TYPE_ACCESS_CHECKER
:
961 dir_config
->access_checker
= auth_server
;
962 dir_config
->access_checker_options
|= (compat
) ? FCGI_COMPAT
: 0;
969 const char *fcgi_config_set_authoritative_slot(const cmd_parms
* const cmd
,
970 fcgi_dir_config
* const dir_config
, int arg
)
972 int offset
= (int)(long)cmd
->info
;
975 *((u_char
*)dir_config
+ offset
) |= FCGI_AUTHORITATIVE
;
977 *((u_char
*)dir_config
+ offset
) &= ~FCGI_AUTHORITATIVE
;