mod_authnz_fcgi.c revision 7a42584e6f09102c6776454f090b98a58fd590eb
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein/* Licensed to the Apache Software Foundation (ASF) under one or more
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * contributor license agreements. See the NOTICE file distributed with
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * this work for additional information regarding copyright ownership.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * The ASF licenses this file to You under the Apache License, Version 2.0
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * (the "License"); you may not use this file except in compliance with
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * the License. You may obtain a copy of the License at
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * Unless required by applicable law or agreed to in writing, software
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * distributed under the License is distributed on an "AS IS" BASIS,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * See the License for the specific language governing permissions and
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * limitations under the License.
b0fb330a8581c8bfab5e523084f9f39264a52b12gsteintypedef struct {
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein const char *backend; /* backend address, as configured */
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein const char *host;
b0fb330a8581c8bfab5e523084f9f39264a52b12gsteintypedef struct {
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein const char *default_user; /* this is user if authorizer returns
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * success and a user expression yields
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * empty string
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein ap_expr_info_t *user_expr; /* expr to evaluate to set r->user */
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein char authoritative; /* fail request if user is rejected? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein char require_basic_auth; /* fail if client didn't send credentials? */
b0fb330a8581c8bfab5e523084f9f39264a52b12gsteintypedef struct {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* If an "authnz" provider successfully authenticates, record
f4c310fd2555c6faca1f980f00b161eadb089023gstein * the provider name here for checking during authz.
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic apr_hash_t *fcgi_authn_providers, *fcgi_authz_providers;
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* fcgi://{hostname|IPv4|IPv6}:port[/] */
f4c310fd2555c6faca1f980f00b161eadb089023gstein#define FCGI_BACKEND_REGEX_STR "m%^fcgi://(.*):(\\d{1,5})/?$%"
f4c310fd2555c6faca1f980f00b161eadb089023gstein * utility function to connect to a peer; generally useful, but
f4c310fd2555c6faca1f980f00b161eadb089023gstein * wait for AF_UNIX support in this mod before thinking about how
f4c310fd2555c6faca1f980f00b161eadb089023gstein * to make it available to other modules
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic apr_status_t connect_to_peer(apr_socket_t **newsock,
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_status_t rv = APR_EINVAL; /* returned if no backend addr was provided
f4c310fd2555c6faca1f980f00b161eadb089023gstein "for target %s",
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void log_provider_info(const fcgi_provider_conf *conf, request_rec *r)
f4c310fd2555c6faca1f980f00b161eadb089023gstein APLOGNO(02496) "name %s, backend %s, host %s, port %d, "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "first address %pI, %c%c",
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void setupenv(request_rec *r, const char *password, const char *apache_role)
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_table_setn(r->subprocess_env, "FCGI_ROLE", AP_FCGI_AUTHORIZER_STR);
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_table_setn(r->subprocess_env, "FCGI_APACHE_ROLE", apache_role);
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_table_setn(r->subprocess_env, "REMOTE_PASSWD", password);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Drop the variables CONTENT_LENGTH, PATH_INFO, PATH_TRANSLATED,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * SCRIPT_NAME and most Hop-By-Hop headers - EXCEPT we will pass
f4c310fd2555c6faca1f980f00b161eadb089023gstein * PROXY_AUTH to allow CGI to perform proxy auth for httpd
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_table_unset(r->subprocess_env, "CONTENT_LENGTH");
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_table_unset(r->subprocess_env, "PATH_TRANSLATED");
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_table_unset(r->subprocess_env, "HTTP_KEEP_ALIVE");
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_table_unset(r->subprocess_env, "HTTP_TRANSFER_ENCODING");
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Connection hop-by-hop header to prevent the CGI from hanging */
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_table_setn(r->subprocess_env, "HTTP_CONNECTION", "close");
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic apr_status_t recv_data(const fcgi_provider_conf *conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_rdata(APLOG_MARK, APLOG_TRACE5, r, "FastCGI data received",
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic apr_status_t recv_data_full(const fcgi_provider_conf *conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein rv = recv_data(conf, r, s, buf + cumulative_len, &readlen);
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic apr_status_t sendv_data(const fcgi_provider_conf *conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (i = 0; i < nvec; i++) {
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein ap_log_rdata(APLOG_MARK, APLOG_TRACE5, r, "FastCGI data sent",
f4c310fd2555c6faca1f980f00b161eadb089023gstein vec[i].iov_base, vec[i].iov_len, AP_LOG_DATA_SHOW_OFFSET);
f4c310fd2555c6faca1f980f00b161eadb089023gstein rv = apr_socket_sendv(s, vec + offset, nvec - offset, &n);
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein if (n > 0) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein break; /* short circuit out */
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagsteinstatic apr_status_t send_begin_request(request_rec *r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_fcgi_fill_in_header(&header, AP_FCGI_BEGIN_REQUEST, request_id,
f4c310fd2555c6faca1f980f00b161eadb089023gstein sizeof(abrb), 0);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_fcgi_fill_in_request_body(&brb, role, 0 /* *NOT* AP_FCGI_KEEP_CONN */);
f4c310fd2555c6faca1f980f00b161eadb089023gstein "%s: '%s': '%s'",
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Send envvars over in as many FastCGI records as it takes, */
f4c310fd2555c6faca1f980f00b161eadb089023gstein avail_len = 16 * 1024; /* our limit per record, which could have been up
f4c310fd2555c6faca1f980f00b161eadb089023gstein * to AP_FCGI_MAX_CONTENT_LEN
f4c310fd2555c6faca1f980f00b161eadb089023gstein required_len = ap_fcgi_encoded_env_len(r->subprocess_env,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* skip this envvar and continue */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* only an unused element at the end of the array */
f4c310fd2555c6faca1f980f00b161eadb089023gstein APLOGNO(02500) "required len for encoding envvars: %"
f4c310fd2555c6faca1f980f00b161eadb089023gstein rv = ap_fcgi_encode_env(r, r->subprocess_env, body, required_len,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* we pre-compute, so we can't run out of space */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* compute and encode must be in sync */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_fcgi_fill_in_header(&header, AP_FCGI_PARAMS, request_id,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Envvars sent, so say we're done */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_fcgi_fill_in_header(&header, AP_FCGI_PARAMS, request_id, 0, 0);
f4c310fd2555c6faca1f980f00b161eadb089023gstein * This header-state logic is from mod_proxy_fcgi.
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* Try to find the end of the script headers in the response from the back
f4c310fd2555c6faca1f980f00b161eadb089023gstein * end fastcgi server. STATE holds the current header parsing state for this
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Returns 0 if it can't find the end of the headers, and 1 if it found the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * end of the headers. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein switch (*state) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein switch (*state) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein * handle_response() is based on mod_proxy_fcgi's dispatch()
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic apr_status_t handle_response(const fcgi_provider_conf *conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein *rspbuflen = 0; /* unless we actually read something */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ob = apr_brigade_create(r->pool, r->connection->bucket_alloc);
f4c310fd2555c6faca1f980f00b161eadb089023gstein while (!done && rv == APR_SUCCESS) { /* Keep reading FastCGI records until
f4c310fd2555c6faca1f980f00b161eadb089023gstein * we get AP_FCGI_END_REQUEST (done)
f4c310fd2555c6faca1f980f00b161eadb089023gstein * or an error occurs.
f4c310fd2555c6faca1f980f00b161eadb089023gstein unsigned char plen;
f4c310fd2555c6faca1f980f00b161eadb089023gstein unsigned char type;
f4c310fd2555c6faca1f980f00b161eadb089023gstein unsigned char version;
f4c310fd2555c6faca1f980f00b161eadb089023gstein rv = recv_data_full(conf, r, s, (char *)farray, AP_FCGI_HEADER_LEN);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_fcgi_header_fields_from_array(&version, &type, &rid, &clen, &plen,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "request id %d, expected %d",
f4c310fd2555c6faca1f980f00b161eadb089023gstein recv_again: /* if we need to keep reading more of a record's content */
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Now get the actual content of the record.
252e2478cb56afb5ca8585b50bc2ffb780d2efb6gstein case AP_FCGI_STDOUT: /* Response headers and optional body */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (clen != 0) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein "parsing -> %d/%d",
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* should not occur for these bucket types;
f4c310fd2555c6faca1f980f00b161eadb089023gstein * does not indicate overflow
f4c310fd2555c6faca1f980f00b161eadb089023gstein "flattening response body",
f4c310fd2555c6faca1f980f00b161eadb089023gstein "script headers from %s",
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* We're still looking for the end of the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * headers, so this part of the data will need
f4c310fd2555c6faca1f980f00b161eadb089023gstein * to persist. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* If we didn't read all the data go back and get the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * rest of it. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Read/discard any trailing padding.
f4c310fd2555c6faca1f980f00b161eadb089023gstein APLOGNO(02510) "%s: Never reached end of script headers",
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* almost from mod_fcgid */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* When the application gives a 200 response, the server ignores response
f4c310fd2555c6faca1f980f00b161eadb089023gstein headers whose names aren't prefixed with Variable- prefix, and ignores
f4c310fd2555c6faca1f980f00b161eadb089023gstein any response content */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int fix_auth_header(void *vr, const char *key, const char *val)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r, "moving %s->%s", key, val);
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void req_rsp(request_rec *r, const fcgi_provider_conf *conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein *rspbuflen = 0; /* unless we actually read something */
f4c310fd2555c6faca1f980f00b161eadb089023gstein rv = send_begin_request(r, conf, s, AP_FCGI_AUTHORIZER, request_id);
f4c310fd2555c6faca1f980f00b161eadb089023gstein rv = send_environment(s, conf, r, request_id, temp_pool);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* The responder owns the request body, not the authorizer.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Don't even send an empty AP_FCGI_STDIN block. libfcgi doesn't care,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * but it wasn't sent to authorizers by mod_fastcgi or mod_fcgi and
f4c310fd2555c6faca1f980f00b161eadb089023gstein * may be unhandled by the app. Additionally, the FastCGI spec does
f4c310fd2555c6faca1f980f00b161eadb089023gstein * not mention FCGI_STDIN in the Authorizer description, though it
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein * does describe FCGI_STDIN elsewhere in more general terms than
f4c310fd2555c6faca1f980f00b161eadb089023gstein * simply a wrapper for the client's request body.
f4c310fd2555c6faca1f980f00b161eadb089023gstein rv = handle_response(conf, r, s, temp_pool, request_id, rspbuf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* some sort of mechanical problem */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* An Authorizer application's 200 response may include headers
f4c310fd2555c6faca1f980f00b161eadb089023gstein * whose names are prefixed with Variable-, and they should be
f4c310fd2555c6faca1f980f00b161eadb089023gstein * available to subsequent phases via subprocess_env (and yanked
f4c310fd2555c6faca1f980f00b161eadb089023gstein * from the client response).
f4c310fd2555c6faca1f980f00b161eadb089023gstein fcgi_dir_conf *dconf = ap_get_module_config(r->per_dir_config,
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *prov;
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *auth_type;
f4c310fd2555c6faca1f980f00b161eadb089023gstein char rspbuf[NON200_RESPONSE_BUF_LEN + 1]; /* extra byte for '\0' */
f4c310fd2555c6faca1f980f00b161eadb089023gstein "require-basic %s, user expr? %s type %s",
f4c310fd2555c6faca1f980f00b161eadb089023gstein conf = apr_hash_get(fcgi_authn_providers, prov, APR_HASH_KEY_STRING);
f4c310fd2555c6faca1f980f00b161eadb089023gstein APLOGNO(02518) "%s: can't find config for provider %s",
f4c310fd2555c6faca1f980f00b161eadb089023gstein req_rsp(r, conf, password, AP_FCGI_APACHE_ROLE_AUTHENTICATOR_STR,
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *err;
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *user = ap_expr_str_exec(r, dconf->user_expr,
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (user) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein "after calling authorizer: user expression "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "yielded empty string (variable not set?)",
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* unexpected error, not even an empty string was returned */
f4c310fd2555c6faca1f980f00b161eadb089023gstein "after calling authorizer: %s",
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* combined authn/authz phase, so app won't be invoked for authz
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Remember that the request was successfully authorized by this
f4c310fd2555c6faca1f980f00b161eadb089023gstein * provider.
f4c310fd2555c6faca1f980f00b161eadb089023gstein fcgi_request_notes *rnotes = apr_palloc(r->pool, sizeof(*rnotes));
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_set_module_config(r->request_config, &authnz_fcgi_module,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* From the spec:
f4c310fd2555c6faca1f980f00b161eadb089023gstein * For Authorizer response status values other than "200" (OK), the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Web server denies access and sends the response status, headers,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * and content back to the HTTP client.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * This only makes sense if this authorizer is authoritative.
f4c310fd2555c6faca1f980f00b161eadb089023gstein APLOGNO(02522) "%s: Ignoring response body from non-"
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (rspbuflen > 0) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* apr_brigade_flatten() interface :( */
f4c310fd2555c6faca1f980f00b161eadb089023gstein rspbuf[rspbuflen] = '\0'; /* we reserved an extra byte for '\0' */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_custom_response(r, r->status, rspbuf); /* API makes a copy */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic authn_status fcgi_check_password(request_rec *r, const char *user,
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *password)
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *prov = apr_table_get(r->notes, AUTHN_PROVIDER_NAME_NOTE);
f4c310fd2555c6faca1f980f00b161eadb089023gstein conf = apr_hash_get(fcgi_authn_providers, prov, APR_HASH_KEY_STRING);
f4c310fd2555c6faca1f980f00b161eadb089023gstein APLOGNO(02526) "%s: can't find config for provider %s",
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* combined authn and authz: FCGI_APACHE_ROLE not set */
f4c310fd2555c6faca1f980f00b161eadb089023gstein conf->is_authz ? NULL : AP_FCGI_APACHE_ROLE_AUTHENTICATOR_STR,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* combined authn/authz phase, so app won't be invoked for authz
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Remember that the request was successfully authorized by this
f4c310fd2555c6faca1f980f00b161eadb089023gstein * provider.
f4c310fd2555c6faca1f980f00b161eadb089023gstein fcgi_request_notes *rnotes = apr_palloc(r->pool, sizeof(*rnotes));
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_set_module_config(r->request_config, &authnz_fcgi_module,
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *prov = apr_table_get(r->notes, AUTHZ_PROVIDER_NAME_NOTE);
f4c310fd2555c6faca1f980f00b161eadb089023gstein conf = apr_hash_get(fcgi_authz_providers, prov, APR_HASH_KEY_STRING);
f4c310fd2555c6faca1f980f00b161eadb089023gstein APLOGNO(02529) "%s: can't find config for provider %s",
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* combined authn/authz phase, so app won't be invoked for authz
f4c310fd2555c6faca1f980f00b161eadb089023gstein * If the provider already successfully authorized this request,
f4c310fd2555c6faca1f980f00b161eadb089023gstein fcgi_request_notes *rnotes = ap_get_module_config(r->request_config,
f4c310fd2555c6faca1f980f00b161eadb089023gstein && !strcmp(rnotes->successful_authnz_provider, conf->name)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein req_rsp(r, conf, NULL, AP_FCGI_APACHE_ROLE_AUTHORIZER_STR, NULL, NULL);
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic const char *fcgi_authz_parse(cmd_parms *cmd, const char *require_line,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Allowed form: Require [not] registered-provider-name<EOS>
f4c310fd2555c6faca1f980f00b161eadb089023gstein return "mod_authnz_fcgi doesn't support restrictions on providers "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "(i.e., multiple require args)";
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic const char *fcgi_check_authn_provider(cmd_parms *cmd,
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *const argv[])
f4c310fd2555c6faca1f980f00b161eadb089023gstein return apr_pstrcat(cmd->pool, dname, ": No provider given", NULL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein return "Options aren't supported with \"None\"";
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* at present, everything needs an argument */
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *err;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int flags = AP_EXPR_FLAG_DONT_VARY | AP_EXPR_FLAG_RESTRICTED
f4c310fd2555c6faca1f980f00b161eadb089023gstein return apr_psprintf(cmd->pool, "%s: Error parsing '%s': '%s'",
f4c310fd2555c6faca1f980f00b161eadb089023gstein return apr_pstrcat(cmd->pool, dname, ": Unexpected option '",
f4c310fd2555c6faca1f980f00b161eadb089023gstein return apr_pstrcat(cmd->pool, dname, ": Bad argument '",
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* AuthnzFcgiAuthDefineProvider {authn|authz|authnz} provider-name \
f4c310fd2555c6faca1f980f00b161eadb089023gstein * fcgi://backendhost:backendport/
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic const char *fcgi_define_provider(cmd_parms *cmd,
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *const argv[])
f4c310fd2555c6faca1f980f00b161eadb089023gstein fcgi_provider_conf *conf = apr_pcalloc(cmd->pool, sizeof(*conf));
f4c310fd2555c6faca1f980f00b161eadb089023gstein fcgi_backend_regex = ap_rxplus_compile(cmd->pool, FCGI_BACKEND_REGEX_STR);
f4c310fd2555c6faca1f980f00b161eadb089023gstein "%s: failed to compile regexec '%s'",
f4c310fd2555c6faca1f980f00b161eadb089023gstein return apr_pstrcat(cmd->pool, dname, ": No type given", NULL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ": Invalid provider type ",
f4c310fd2555c6faca1f980f00b161eadb089023gstein return apr_pstrcat(cmd->pool, dname, ": No provider name given", NULL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein return apr_pstrcat(cmd->pool, dname, ": No backend-address given",
f4c310fd2555c6faca1f980f00b161eadb089023gstein rc = ap_rxplus_exec(cmd->pool, fcgi_backend_regex, argv[ca], NULL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!rc || ap_rxplus_nmatch(fcgi_backend_regex) != 3) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein "' has invalid form",
f4c310fd2555c6faca1f980f00b161eadb089023gstein host = ap_rxplus_pmatch(cmd->pool, fcgi_backend_regex, 1);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (host[0] == '[' && host[strlen(host) - 1] == ']') {
f4c310fd2555c6faca1f980f00b161eadb089023gstein conf->port = atoi(ap_rxplus_pmatch(cmd->pool, fcgi_backend_regex, 2));
f4c310fd2555c6faca1f980f00b161eadb089023gstein "' has invalid port",
f4c310fd2555c6faca1f980f00b161eadb089023gstein rv = apr_sockaddr_info_get(&conf->backend_addrs, conf->host,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, rv, NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ": Error resolving backend address",
f4c310fd2555c6faca1f980f00b161eadb089023gstein ": Unexpected parameter ",
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_hash_set(fcgi_authn_providers, conf->name, APR_HASH_KEY_STRING,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_register_auth_provider(cmd->pool, AUTHN_PROVIDER_GROUP,
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_hash_set(fcgi_authz_providers, conf->name, APR_HASH_KEY_STRING,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_register_auth_provider(cmd->pool, AUTHZ_PROVIDER_GROUP,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Define a FastCGI authn and/or authz provider"),
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Enable/disable a FastCGI authorizer to handle "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "check_authn phase"),
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int fcgi_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
f4c310fd2555c6faca1f980f00b161eadb089023gstein static const char * const auth_basic_runs_after_me[] =
f4c310fd2555c6faca1f980f00b161eadb089023gstein {"mod_auth_basic.c", NULL}; /* to allow for custom response */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_hook_pre_config(fcgi_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_hook_check_authn(fcgi_check_authn, NULL, auth_basic_runs_after_me,
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void *create_dir_conf(apr_pool_t *p, char *dummy)
f4c310fd2555c6faca1f980f00b161eadb089023gstein fcgi_dir_conf *dconf = apr_pcalloc(p, sizeof(fcgi_dir_conf));
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void *merge_dir_conf(apr_pool_t *p, void *basev, void *overridesv)
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein fcgi_dir_conf *a = (fcgi_dir_conf *)apr_pcalloc(p, sizeof(*a));
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* currently we just have a single directive applicable to a
f4c310fd2555c6faca1f980f00b161eadb089023gstein * directory, so if it is set then grab all fields from fcgi_dir_conf