1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930
|
/*
* $Id: fcgi_config.c,v 1.24 2000/10/23 20:20:49 robs Exp $
*/
#include "fcgi.h"
/*******************************************************************************
* Get the next configuration directive argument, & return an in_addr and port.
* The arg must be in the form "host:port" where host can be an IP or hostname.
* The pool arg should be persistant storage.
*/
static const char *get_host_n_port(pool *p, const char **arg,
const char **host, u_short *port)
{
char *cvptr, *portStr;
long tmp;
*host = ap_getword_conf(p, arg);
if (**host == '\0')
return "\"\"";
portStr = strchr(*host, ':');
if (portStr == NULL)
return "missing port specification";
/* Split the host and port portions */
*portStr++ = '\0';
/* Convert port number */
tmp = (u_short) strtol(portStr, &cvptr, 10);
if (*cvptr != '\0' || tmp < 1 || tmp > USHRT_MAX)
return ap_pstrcat(p, "bad port number \"", portStr, "\"", NULL);
*port = (unsigned short) tmp;
return NULL;
}
/*******************************************************************************
* Get the next configuration directive argument, & return an u_short.
* The pool arg should be temporary storage.
*/
static const char *get_u_short(pool *p, const char **arg,
u_short *num, u_short min)
{
char *ptr;
long tmp;
const char *txt = ap_getword_conf(p, arg);
if (*txt == '\0') {
return "\"\"";
}
tmp = strtol(txt, &ptr, 10);
if (*ptr != '\0') {
return ap_pstrcat(p, "\"", txt, "\" must be a positive integer", NULL);
}
if (tmp < min || tmp > USHRT_MAX) {
return ap_psprintf(p, "\"%u\" must be >= %u and < %u", *num, min, USHRT_MAX);
}
*num = (u_short) tmp;
return NULL;
}
/*******************************************************************************
* Get the next configuration directive argument, & return an u_int.
* The pool arg should be temporary storage.
*/
static const char *get_u_int(pool *p, const char **arg,
u_int *num, u_int min)
{
char *ptr;
const char *val = ap_getword_conf(p, arg);
if (*val == '\0')
return "\"\"";
*num = (u_int)strtol(val, &ptr, 10);
if (*ptr != '\0')
return ap_pstrcat(p, "\"", val, "\" must be a positive integer", NULL);
else if (*num < min)
return ap_psprintf(p, "\"%u\" must be >= %u", *num, min);
return NULL;
}
/*******************************************************************************
* Get the next configuration directive argument, & return a float.
* The pool arg should be temporary storage.
*/
static const char *get_float(pool *p, const char **arg,
float *num, float min, float max)
{
char *ptr;
const char *val = ap_getword_conf(p, arg);
if (*val == '\0')
return "\"\"";
*num = (float) strtod(val, &ptr);
if (*ptr != '\0')
return ap_pstrcat(p, "\"", val, "\" is not a floating point number", NULL);
if (*num < min || *num > max)
return ap_psprintf(p, "\"%f\" is not between %f and %f", *num, min, max);
return NULL;
}
const char *fcgi_config_set_env_var(pool *p, char **envp, unsigned int *envc, char * var)
{
if (*envc >= MAX_INIT_ENV_VARS) {
return "too many variables, must be <= MAX_INIT_ENV_VARS";
}
if (strchr(var, '=') == NULL) {
*(envp + *envc) = ap_pstrcat(p, var, "=", getenv(var), NULL);
}
else {
*(envp + *envc) = var;
}
(*envc)++;
return NULL;
}
/*******************************************************************************
* Get the next configuration directive argument, & add it to an env array.
* The pool arg should be permanent storage.
*/
static const char *get_env_var(pool *p, const char **arg, char **envp, unsigned int *envc)
{
char * const val = ap_getword_conf(p, arg);
if (*val == '\0') {
return "\"\"";
}
return fcgi_config_set_env_var(p, envp, envc, val);
}
static const char *get_pass_header(pool *p, const char **arg, array_header **array)
{
const char **header;
if (!*array) {
*array = ap_make_array(p, 10, sizeof(char*));
}
header = (const char **)ap_push_array(*array);
*header = ap_getword_conf(p, arg);
return header ? NULL : "\"\"";
}
/*******************************************************************************
* Return a "standard" message for common configuration errors.
*/
static const char *invalid_value(pool *p, const char *cmd, const char *id,
const char *opt, const char *err)
{
return ap_psprintf(p, "%s%s%s: invalid value for %s: %s",
cmd, id ? " " : "", id ? id : "", opt, err);
}
/*******************************************************************************
* Set/Reset the uid/gid that Apache and the PM will run as. This is ap_user_id
* and ap_group_id if we're started as root, and euid/egid otherwise. Also try
* to check that the config files don't set the User/Group after a FastCGI
* directive is used that depends on it.
*/
/*@@@ To be complete, we should save a handle to the server each AppClass is
* configured in and at init() check that the user/group is still what we
* thought it was. Also the other directives should only be allowed in the
* parent Apache server.
*/
const char *fcgi_config_set_fcgi_uid_n_gid(int set)
{
static int isSet = 0;
#ifndef WIN32
uid_t uid = geteuid();
gid_t gid = getegid();
if (set == 0) {
isSet = 0;
fcgi_user_id = (uid_t)-1;
fcgi_group_id = (gid_t)-1;
return NULL;
}
uid = uid ? uid : ap_user_id;
gid = gid ? gid : ap_group_id;
if (isSet && (uid != fcgi_user_id || gid != fcgi_group_id)) {
return "User/Group commands must preceed FastCGI server definitions";
}
isSet = 1;
fcgi_user_id = uid;
fcgi_group_id = gid;
#endif
return NULL;
}
void fcgi_config_reset_globals(void* dummy)
{
fcgi_config_pool = NULL;
fcgi_servers = NULL;
fcgi_config_set_fcgi_uid_n_gid(0);
fcgi_wrapper = NULL;
fcgi_socket_dir = DEFAULT_SOCK_DIR;
fcgi_dynamic_total_proc_count = 0;
fcgi_dynamic_epoch = 0;
fcgi_dynamic_last_analyzed = 0;
dynamicMaxProcs = FCGI_DEFAULT_MAX_PROCS;
dynamicMinProcs = FCGI_DEFAULT_MIN_PROCS;
dynamicMaxClassProcs = FCGI_DEFAULT_MAX_CLASS_PROCS;
dynamicKillInterval = FCGI_DEFAULT_KILL_INTERVAL;
dynamicUpdateInterval = FCGI_DEFAULT_UPDATE_INTERVAL;
dynamicGain = FCGI_DEFAULT_GAIN;
dynamicThreshhold1 = FCGI_DEFAULT_THRESHHOLD_1;
dynamicThreshholdN = FCGI_DEFAULT_THRESHHOLD_N;
dynamicPleaseStartDelay = FCGI_DEFAULT_START_PROCESS_DELAY;
dynamicAppConnectTimeout = FCGI_DEFAULT_APP_CONN_TIMEOUT;
dynamicEnvp = &fcgi_empty_env;
dynamicProcessSlack = FCGI_DEFAULT_PROCESS_SLACK;
dynamicAutoRestart = FCGI_DEFAULT_RESTART_DYNAMIC;
dynamicAutoUpdate = FCGI_DEFAULT_AUTOUPDATE;
dynamicListenQueueDepth = FCGI_DEFAULT_LISTEN_Q;
dynamicInitStartDelay = DEFAULT_INIT_START_DELAY;
dynamicRestartDelay = FCGI_DEFAULT_RESTART_DELAY;
dynamic_pass_headers = NULL;
dynamic_idle_timeout = FCGI_DEFAULT_IDLE_TIMEOUT;
}
/*******************************************************************************
* Create a directory to hold Unix/Domain sockets.
*/
const char *fcgi_config_make_dir(pool *tp, char *path)
{
struct stat finfo;
const char *err = NULL;
/* Is the directory spec'd correctly */
if (*path != '/') {
return "path is not absolute (it must start with a \"/\")";
}
else {
int i = strlen(path) - 1;
/* Strip trailing "/"s */
while(i > 0 && path[i] == '/') path[i--] = '\0';
}
/* Does it exist? */
if (stat(path, &finfo) != 0) {
/* No, but maybe we can create it */
#ifdef WIN32
if (mkdir(path) != 0)
#else
if (mkdir(path, S_IRWXU) != 0)
#endif
{
return ap_psprintf(tp,
"doesn't exist and can't be created: %s",
strerror(errno));
}
#ifndef WIN32
/* If we're root, we're gonna setuid/setgid so we need to chown */
if (geteuid() == 0 && chown(path, ap_user_id, ap_group_id) != 0) {
return ap_psprintf(tp,
"can't chown() to the server (uid %ld, gid %ld): %s",
(long)ap_user_id, (long)ap_group_id, strerror(errno));
}
#endif
}
else {
/* Yes, is it a directory? */
if (!S_ISDIR(finfo.st_mode))
return "isn't a directory!";
/* Can we RWX in there? */
#ifdef WIN32
err = fcgi_util_check_access(tp, NULL, &finfo, _S_IREAD | _S_IWRITE | _S_IEXEC, fcgi_user_id, fcgi_group_id);
#else
err = fcgi_util_check_access(tp, NULL, &finfo, R_OK | W_OK | X_OK,
fcgi_user_id, fcgi_group_id);
#endif
if (err != NULL) {
return ap_psprintf(tp,
"access for server (uid %ld, gid %ld) failed: %s",
(long)fcgi_user_id, (long)fcgi_group_id, err);
}
}
return NULL;
}
/*******************************************************************************
* Create a "dynamic" subdirectory. If the directory
* already exists we don't mess with it unless 'wax' is set.
*/
const char *fcgi_config_make_dynamic_dir(pool *p, const int wax)
{
#ifndef WIN32
DIR *dp = NULL;
struct dirent *dirp = NULL;
const char *err;
pool *tp;
fcgi_dynamic_dir = ap_pstrcat(p, fcgi_socket_dir, "/dynamic", NULL);
if ((err = fcgi_config_make_dir(p, fcgi_dynamic_dir)))
return ap_psprintf(p, "can't create dynamic directory \"%s\": %s", fcgi_dynamic_dir, err);
/* Don't step on a running server unless its OK. */
if (!wax)
return NULL;
/* Create a subpool for the directory operations */
tp = ap_make_sub_pool(p);
dp = ap_popendir(tp, fcgi_dynamic_dir);
if (dp == NULL) {
ap_destroy_pool(tp);
return ap_psprintf(p, "can't open dynamic directory \"%s\": %s",
fcgi_dynamic_dir, strerror(errno));
}
/* Delete everything in the directory, its all FCGI specific */
while ((dirp = readdir(dp)) != NULL) {
if (strcmp(dirp->d_name, ".") == 0
|| strcmp(dirp->d_name, "..") == 0) {
continue;
}
unlink(ap_pstrcat(tp, fcgi_dynamic_dir, "/", dirp->d_name, NULL));
}
ap_destroy_pool(tp);
#else
fcgi_dynamic_dir = ap_pstrcat(p, fcgi_socket_dir, "dynamic", NULL);
#endif
return NULL;
}
/*******************************************************************************
* Change the directory used for the Unix/Domain sockets from the default.
* Create the directory and the "dynamic" subdirectory.
*/
const char *fcgi_config_set_socket_dir(cmd_parms *cmd, void *dummy, char *arg)
{
pool * const tp = cmd->temp_pool;
const char * const name = cmd->cmd->name;
const char *err;
if (strcmp(fcgi_socket_dir, DEFAULT_SOCK_DIR) != 0) {
return ap_psprintf(tp, "%s %s: already defined as \"%s\"",
name, arg, fcgi_socket_dir);
}
err = fcgi_config_set_fcgi_uid_n_gid(1);
if (err != NULL)
return ap_psprintf(tp, "%s %s: %s", name, arg, err);
if (fcgi_servers != NULL) {
return ap_psprintf(tp,
"The %s command must preceed static FastCGI server definitions",
name);
}
#ifndef WIN32
arg = ap_os_canonical_filename(cmd->pool, arg);
arg = ap_server_root_relative(cmd->pool, arg);
#else
if (strncmp(arg, "\\\\.\\pipe\\", 9) != 0)
return ap_psprintf(tp, "%s %s is invalid format",name, arg);
#endif
fcgi_socket_dir = arg;
#ifndef WIN32
err = fcgi_config_make_dir(tp, fcgi_socket_dir);
if (err != NULL)
return ap_psprintf(tp, "%s %s: %s", name, arg, err);
err = fcgi_config_make_dynamic_dir(cmd->pool, 0);
if (err != NULL)
return ap_psprintf(tp, "%s %s: %s", name, arg, err);
#endif
return NULL;
}
/*******************************************************************************
* Enable, disable, or specify the path to a wrapper used to invoke all
* FastCGI applications.
*/
const char *fcgi_config_set_wrapper(cmd_parms *cmd, void *dummy, const char *arg)
{
const char *err = NULL;
const char * const name = cmd->cmd->name;
pool * const tp = cmd->temp_pool;
char * wrapper;
if (!ap_suexec_enabled && strcasecmp(arg, "On") == 0) {
fprintf(stderr, "Warning: \"%s On\" requires SUEXEC be enabled in Apache", name);
return NULL;
}
err = fcgi_config_set_fcgi_uid_n_gid(1);
if (err != NULL)
return ap_psprintf(tp, "%s %s: %s", name, arg, err);
if (fcgi_servers != NULL) {
return ap_psprintf(tp,
"The %s command must preceed static FastCGI server definitions", name);
}
if (strcasecmp(arg, "On") == 0) {
fcgi_wrapper = SUEXEC_BIN;
}
else if (strcasecmp(arg, "Off") == 0) {
fcgi_wrapper = NULL;
}
else {
wrapper = (char *) ap_os_canonical_filename(cmd->pool, arg);
wrapper = ap_server_root_relative(cmd->pool, wrapper);
#ifdef WIN32
err = fcgi_util_check_access(tp, wrapper, NULL, _S_IEXEC, fcgi_user_id, fcgi_group_id);
#else
err = fcgi_util_check_access(tp, wrapper, NULL, X_OK, fcgi_user_id, fcgi_group_id);
#endif
if (err != NULL) {
return ap_psprintf(tp,
"%s: \"%s\" access for server (uid %ld, gid %ld) failed: %s",
name, wrapper, (long)fcgi_user_id, (long)fcgi_group_id, err);
}
fcgi_wrapper = wrapper;
}
return NULL;
}
/*******************************************************************************
* Configure a static FastCGI server.
*/
const char *fcgi_config_new_static_server(cmd_parms *cmd, void *dummy, const char *arg)
{
fcgi_server *s;
pool *p = cmd->pool, *tp = cmd->temp_pool;
const char *name = cmd->cmd->name;
char *fs_path = ap_getword_conf(p, &arg);
const char *option, *err;
/* Allocate temp storage for the array of initial environment variables */
char **envp = ap_pcalloc(tp, sizeof(char *) * (MAX_INIT_ENV_VARS + 3));
unsigned int envc = 0;
if (*fs_path == '\0')
return "AppClass requires a pathname!?";
if ((err = fcgi_config_set_fcgi_uid_n_gid(1)) != NULL)
return ap_psprintf(tp, "%s %s: %s", name, fs_path, err);
fs_path = ap_os_canonical_filename(p, fs_path);
fs_path = ap_server_root_relative(p, fs_path);
ap_getparents(fs_path);
ap_no2slash(fs_path);
/* See if we've already got one of these configured */
s = fcgi_util_fs_get_by_id(fs_path, cmd->server->server_uid,
cmd->server->server_gid);
if (s != NULL) {
if (fcgi_wrapper) {
return ap_psprintf(tp,
"%s: redefinition of a previously defined FastCGI server \"%s\" with uid=%ld and gid=%ld",
name, fs_path, (long)cmd->server->server_uid,
(long)cmd->server->server_gid);
}
else {
return ap_psprintf(tp,
"%s: redefinition of a previously defined FastCGI server \"%s\"",
name, fs_path);
}
}
err = fcgi_util_fs_is_path_ok(tp, fs_path, NULL, cmd->server->server_uid,
cmd->server->server_gid);
if (err != NULL) {
return ap_psprintf(tp, "%s: \"%s\" %s", name, fs_path, err);
}
s = fcgi_util_fs_new(p);
s->fs_path = fs_path;
s->directive = APP_CLASS_STANDARD;
s->restartOnExit = TRUE;
s->numProcesses = 1;
#ifdef WIN32
// TCP FastCGI applications require SystemRoot be present in the environment
// Put it in both for consistency to the application
fcgi_config_set_env_var(tp, envp, &envc, "SystemRoot");
#else
if (fcgi_wrapper) {
struct passwd *pw;
struct group *gr;
s->uid = cmd->server->server_uid;
pw = getpwuid(s->uid);
if (pw == NULL) {
return ap_psprintf(tp, "mod_fastcgi: "
"getpwuid() couldn't determine the username for uid '%ld', "
"you probably need to modify the User directive: %s",
(long)s->uid, strerror(errno));
}
s->user = ap_pstrdup(p, pw->pw_name);
s->username = s->user;
s->gid = cmd->server->server_gid;
gr = getgrgid(s->gid);
if (gr == NULL) {
return ap_psprintf(tp, "mod_fastcgi: "
"getgrgid() couldn't determine the group name for gid '%ld', "
"you probably need to modify the Group directive: %s\n",
(long)s->gid, strerror(errno));
}
s->group = ap_pstrdup(p, gr->gr_name);
}
#endif
/* Parse directive arguments */
while (*arg) {
option = ap_getword_conf(tp, &arg);
if (strcasecmp(option, "-processes") == 0) {
if ((err = get_u_int(tp, &arg, &s->numProcesses, 1)))
return invalid_value(tp, name, fs_path, option, err);
}
else if (strcasecmp(option, "-restart-delay") == 0) {
if ((err = get_u_int(tp, &arg, &s->restartDelay, 0)))
return invalid_value(tp, name, fs_path, option, err);
}
else if (strcasecmp(option, "-init-start-delay") == 0) {
if ((err = get_u_int(tp, &arg, &s->initStartDelay, 0)))
return invalid_value(tp, name, fs_path, option, err);
}
else if (strcasecmp(option, "-priority") == 0) {
if ((err = get_u_int(tp, &arg, &s->processPriority, 0)))
return invalid_value(tp, name, fs_path, option, err);
}
else if (strcasecmp(option, "-listen-queue-depth") == 0) {
if ((err = get_u_int(tp, &arg, &s->listenQueueDepth, 1)))
return invalid_value(tp, name, fs_path, option, err);
}
else if (strcasecmp(option, "-appConnTimeout") == 0) {
if ((err = get_u_int(tp, &arg, &s->appConnectTimeout, 0)))
return invalid_value(tp, name, fs_path, option, err);
}
else if (strcasecmp(option, "-idle-timeout") == 0) {
if ((err = get_u_int(tp, &arg, &s->idle_timeout, 1)))
return invalid_value(tp, name, fs_path, option, err);
}
else if (strcasecmp(option, "-port") == 0) {
if ((err = get_u_short(tp, &arg, &s->port, 1)))
return invalid_value(tp, name, fs_path, option, err);
}
else if (strcasecmp(option, "-socket") == 0) {
s->socket_path = ap_getword_conf(tp, &arg);
if (*s->socket_path == '\0')
return invalid_value(tp, name, fs_path, option, "\"\"");
}
else if (strcasecmp(option, "-initial-env") == 0) {
if ((err = get_env_var(p, &arg, envp, &envc)))
return invalid_value(tp, name, fs_path, option, err);
}
else if (strcasecmp(option, "-pass-header") == 0) {
if ((err = get_pass_header(p, &arg, &s->pass_headers)))
return invalid_value(tp, name, fs_path, option, err);
}
else if (strcasecmp(option, "-flush") == 0) {
s->flush = 1;
}
else {
return ap_psprintf(tp, "%s %s: invalid option: %s", name, fs_path, option);
}
} /* while */
if (s->socket_path != NULL && s->port != 0) {
return ap_psprintf(tp,
"%s %s: -port and -socket are mutually exclusive options",
name, fs_path);
}
/* Move env array to a surviving pool, leave an extra slot for WIN32 _FCGI_MUTEX_ */
++envc;
s->envp = (char **)ap_palloc(p, sizeof(char *) * ++envc);
memcpy(s->envp, envp, sizeof(char *) * envc);
/* Initialize process structs */
s->procs = fcgi_util_fs_create_procs(p, s->numProcesses);
/* Build the appropriate sockaddr structure */
if (s->port != 0) {
err = fcgi_util_socket_make_inet_addr(p, (struct sockaddr_in **)&s->socket_addr,
&s->socket_addr_len, NULL, s->port);
if (err != NULL)
return ap_psprintf(tp, "%s %s: %s", name, fs_path, err);
#ifdef WIN32
err = fcgi_util_socket_make_inet_addr(p, (struct sockaddr_in **)&s->dest_addr,
&s->socket_addr_len, "localhost", s->port);
if (err != NULL)
return ap_psprintf(tp, "%s %s: %s", name, fs_path, err);
#endif
} else {
if (s->socket_path == NULL)
s->socket_path = fcgi_util_socket_hash_filename(tp, fs_path, s->user, s->group);
s->socket_path = fcgi_util_socket_make_path_absolute(p, s->socket_path, 0);
#ifndef WIN32
err = fcgi_util_socket_make_domain_addr(p, (struct sockaddr_un **)&s->socket_addr,
&s->socket_addr_len, s->socket_path);
if (err != NULL)
return ap_psprintf(tp, "%s %s: %s", name, fs_path, err);
#endif
}
/* Add it to the list of FastCGI servers */
fcgi_util_fs_add(s);
return NULL;
}
/*******************************************************************************
* Configure a static FastCGI server that is started/managed elsewhere.
*/
const char *fcgi_config_new_external_server(cmd_parms *cmd, void *dummy, const char *arg)
{
fcgi_server *s;
pool * const p = cmd->pool, *tp = cmd->temp_pool;
const char * const name = cmd->cmd->name;
char *fs_path = ap_getword_conf(p, &arg);
const char *option, *err;
if (!*fs_path) {
return ap_pstrcat(tp, name, " requires a path and either a -socket or -host option", NULL);
}
fs_path = ap_os_canonical_filename(p, fs_path);
fs_path = ap_server_root_relative(p, fs_path);
ap_getparents(fs_path);
ap_no2slash(fs_path);
/* See if we've already got one of these bettys configured */
s = fcgi_util_fs_get_by_id(fs_path, cmd->server->server_uid,
cmd->server->server_gid);
if (s != NULL) {
if (fcgi_wrapper) {
return ap_psprintf(tp,
"%s: redefinition of a previously defined class \"%s\" with uid=%ld and gid=%ld",
name, fs_path, (long)cmd->server->server_uid,
(long)cmd->server->server_gid);
}
else {
return ap_psprintf(tp,
"%s: redefinition of previously defined class \"%s\"", name, fs_path);
}
}
s = fcgi_util_fs_new(p);
s->fs_path = fs_path;
s->directive = APP_CLASS_EXTERNAL;
err = fcgi_util_fs_set_uid_n_gid(p, s, cmd->server->server_uid, cmd->server->server_gid);
if (err != NULL)
return ap_psprintf(tp, "%s %s: %s", name, fs_path, err);
/* Parse directive arguments */
while (*arg != '\0') {
option = ap_getword_conf(tp, &arg);
if (strcasecmp(option, "-host") == 0) {
if ((err = get_host_n_port(p, &arg, &s->host, &s->port)))
return invalid_value(tp, name, fs_path, option, err);
}
else if (strcasecmp(option, "-socket") == 0) {
s->socket_path = ap_getword_conf(tp, &arg);
if (*s->socket_path == '\0')
return invalid_value(tp, name, fs_path, option, "\"\"");
}
else if (strcasecmp(option, "-appConnTimeout") == 0) {
if ((err = get_u_int(tp, &arg, &s->appConnectTimeout, 0)))
return invalid_value(tp, name, fs_path, option, err);
}
else if (strcasecmp(option, "-idle-timeout") == 0) {
if ((err = get_u_int(tp, &arg, &s->idle_timeout, 1)))
return invalid_value(tp, name, fs_path, option, err);
}
else if (strcasecmp(option, "-pass-header") == 0) {
if ((err = get_pass_header(p, &arg, &s->pass_headers)))
return invalid_value(tp, name, fs_path, option, err);
}
else if (strcasecmp(option, "-flush") == 0) {
s->flush = 1;
}
else {
return ap_psprintf(tp, "%s %s: invalid option: %s", name, fs_path, option);
}
} /* while */
/* Require one of -socket or -host, but not both */
if (s->socket_path != NULL && s->port != 0) {
return ap_psprintf(tp,
"%s %s: -host and -socket are mutually exclusive options",
name, fs_path);
}
if (s->socket_path == NULL && s->port == 0) {
return ap_psprintf(tp,
"%s %s: -socket or -host option missing", name, fs_path);
}
/* Build the appropriate sockaddr structure */
if (s->port != 0) {
err = fcgi_util_socket_make_inet_addr(p, (struct sockaddr_in **)&s->socket_addr,
&s->socket_addr_len, s->host, s->port);
if (err != NULL)
return ap_psprintf(tp, "%s %s: %s", name, fs_path, err);
} else {
s->socket_path = fcgi_util_socket_make_path_absolute(p, s->socket_path, 0);
#ifndef WIN32
err = fcgi_util_socket_make_domain_addr(p, (struct sockaddr_un **)&s->socket_addr,
&s->socket_addr_len, s->socket_path);
if (err != NULL)
return ap_psprintf(tp, "%s %s: %s", name, fs_path, err);
#endif
}
/* Add it to the list of FastCGI servers */
fcgi_util_fs_add(s);
return NULL;
}
/*
*----------------------------------------------------------------------
*
* fcgi_config_set_config --
*
* Implements the FastCGI FCGIConfig configuration directive.
* This command adds routines to control the execution of the
* dynamic FastCGI processes.
*
*
*----------------------------------------------------------------------
*/
const char *fcgi_config_set_config(cmd_parms *cmd, void *dummy, const char *arg)
{
pool * const p = cmd->pool;
pool * const tp = cmd->temp_pool;
const char *err, *option;
const char * const name = cmd->cmd->name;
/* Allocate temp storage for an initial environment */
unsigned int envc = 0;
char **envp = (char **)ap_pcalloc(tp, sizeof(char *) * (MAX_INIT_ENV_VARS + 3));
/* Parse the directive arguments */
while (*arg) {
option = ap_getword_conf(tp, &arg);
if (strcasecmp(option, "-maxProcesses") == 0) {
if ((err = get_u_int(tp, &arg, &dynamicMaxProcs, 1)))
return invalid_value(tp, name, NULL, option, err);
}
else if (strcasecmp(option, "-minProcesses") == 0) {
if ((err = get_u_int(tp, &arg, &dynamicMinProcs, 0)))
return invalid_value(tp, name, NULL, option, err);
}
else if (strcasecmp(option, "-maxClassProcesses") == 0) {
if ((err = get_u_int(tp, &arg, &dynamicMaxClassProcs, 1)))
return invalid_value(tp, name, NULL, option, err);
}
else if (strcasecmp(option, "-killInterval") == 0) {
if ((err = get_u_int(tp, &arg, &dynamicKillInterval, 1)))
return invalid_value(tp, name, NULL, option, err);
}
else if (strcasecmp(option, "-updateInterval") == 0) {
if ((err = get_u_int(tp, &arg, &dynamicUpdateInterval, 1)))
return invalid_value(tp, name, NULL, option, err);
}
else if (strcasecmp(option, "-gainValue") == 0) {
if ((err = get_float(tp, &arg, &dynamicGain, 0.0, 1.0)))
return invalid_value(tp, name, NULL, option, err);
}
else if (strcasecmp(option, "-singleThreshhold") == 0) {
if ((err = get_u_int(tp, &arg, &dynamicThreshhold1, 0)))
return invalid_value(tp, name, NULL, option, err);
}
else if (strcasecmp(option, "-multiThreshhold") == 0) {
if ((err = get_u_int(tp, &arg, &dynamicThreshholdN, 0)))
return invalid_value(tp, name, NULL, option, err);
}
else if (strcasecmp(option, "-startDelay") == 0) {
if ((err = get_u_int(tp, &arg, &dynamicPleaseStartDelay, 1)))
return invalid_value(tp, name, NULL, option, err);
}
else if (strcasecmp(option, "-initial-env") == 0) {
if ((err = get_env_var(p, &arg, envp, &envc)))
return invalid_value(tp, name, NULL, option, err);
}
else if (strcasecmp(option, "-pass-header") == 0) {
if ((err = get_pass_header(p, &arg, &dynamic_pass_headers)))
return invalid_value(tp, name, NULL, option, err);
}
else if (strcasecmp(option, "-appConnTimeout") == 0) {
if ((err = get_u_int(tp, &arg, &dynamicAppConnectTimeout, 0)))
return invalid_value(tp, name, NULL, option, err);
}
else if (strcasecmp(option, "-idle-timeout") == 0) {
if ((err = get_u_int(tp, &arg, &dynamic_idle_timeout, 1)))
return invalid_value(tp, name, NULL, option, err);
}
else if (strcasecmp(option, "-listen-queue-depth") == 0) {
if ((err = get_u_int(tp, &arg, &dynamicListenQueueDepth, 1)))
return invalid_value(tp, name, NULL, option, err);
}
else if (strcasecmp(option, "-restart-delay") == 0) {
if ((err = get_u_int(tp, &arg, &dynamicRestartDelay, 0)))
return invalid_value(tp, name, NULL, option, err);
}
else if (strcasecmp(option, "-init-start-delay") == 0) {
if ((err = get_u_int(tp, &arg, &dynamicInitStartDelay, 0)))
return invalid_value(tp, name, NULL, option, err);
}
else if (strcasecmp(option, "-processSlack") == 0) {
if ((err = get_u_int(tp, &arg, &dynamicProcessSlack, 1)))
return invalid_value(tp, name, NULL, option, err);
}
else if (strcasecmp(option, "-restart") == 0) {
dynamicAutoRestart = 1;
}
else if (strcasecmp(option, "-autoUpdate") == 0) {
dynamicAutoUpdate = 1;
}
else {
return ap_psprintf(tp, "%s: invalid option: %s", name, option);
}
} /* while */
/* Move env array to a surviving pool, leave an extra slot for WIN32 _FCGI_MUTEX_ */
++envc;
dynamicEnvp = (char **)ap_palloc(p, sizeof(char *) * ++envc);
memcpy(dynamicEnvp, envp, sizeof(char *) * envc);
return NULL;
}
void *fcgi_config_create_dir_config(pool *p, char *dummy)
{
fcgi_dir_config *dir_config = ap_pcalloc(p, sizeof(fcgi_dir_config));
dir_config->authenticator_options = FCGI_AUTHORITATIVE;
dir_config->authorizer_options = FCGI_AUTHORITATIVE;
dir_config->access_checker_options = FCGI_AUTHORITATIVE;
return dir_config;
}
const char *fcgi_config_new_auth_server(cmd_parms * const cmd,
fcgi_dir_config *dir_config, const char *fs_path, const char * const compat)
{
pool * const tp = cmd->temp_pool;
const uid_t uid = cmd->server->server_uid;
const gid_t gid = cmd->server->server_gid;
char * auth_server;
auth_server = (char *) ap_os_canonical_filename(cmd->pool, fs_path);
auth_server = ap_server_root_relative(cmd->pool, auth_server);
/* Make sure its already configured or at least a candidate for dynamic */
if (fcgi_util_fs_get_by_id(auth_server, uid, gid) == NULL) {
const char *err = fcgi_util_fs_is_path_ok(tp, auth_server, NULL, uid, gid);
if (err)
return ap_psprintf(tp, "%s: \"%s\" %s", cmd->cmd->name, auth_server, err);
}
if (compat && strcasecmp(compat, "-compat"))
return ap_psprintf(cmd->temp_pool, "%s: unknown option: \"%s\"", cmd->cmd->name, compat);
switch((int)cmd->info) {
case FCGI_AUTH_TYPE_AUTHENTICATOR:
dir_config->authenticator = auth_server;
dir_config->authenticator_options |= (compat) ? FCGI_COMPAT : 0;
break;
case FCGI_AUTH_TYPE_AUTHORIZER:
dir_config->authorizer = auth_server;
dir_config->authorizer_options |= (compat) ? FCGI_COMPAT : 0;
break;
case FCGI_AUTH_TYPE_ACCESS_CHECKER:
dir_config->access_checker = auth_server;
dir_config->access_checker_options |= (compat) ? FCGI_COMPAT : 0;
break;
}
return NULL;
}
const char *fcgi_config_set_authoritative_slot(const cmd_parms * const cmd,
fcgi_dir_config * const dir_config, int arg)
{
int offset = (int)(long)cmd->info;
if (arg)
*(int *)(dir_config + offset) |= FCGI_AUTHORITATIVE;
else
*(int *)(dir_config + offset) &= ~FCGI_AUTHORITATIVE;
return NULL;
}
|