mod_authn_dbd.c revision df9ae8c422035307555bba24cc1d5f5c208890dc
6ae232055d4d8a97267517c5e50074c2c819941and/* Licensed to the Apache Software Foundation (ASF) under one or more
6ae232055d4d8a97267517c5e50074c2c819941and * contributor license agreements. See the NOTICE file distributed with
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * this work for additional information regarding copyright ownership.
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * The ASF licenses this file to You under the Apache License, Version 2.0
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * (the "License"); you may not use this file except in compliance with
6ae232055d4d8a97267517c5e50074c2c819941and * the License. You may obtain a copy of the License at
96ad5d81ee4a2cc66a4ae19893efc8aa6d06fae7jailletc * Unless required by applicable law or agreed to in writing, software
6ae232055d4d8a97267517c5e50074c2c819941and * distributed under the License is distributed on an "AS IS" BASIS,
6ae232055d4d8a97267517c5e50074c2c819941and * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * See the License for the specific language governing permissions and
2e545ce2450a9953665f701bb05350f0d3f26275nd * limitations under the License.
1ac39787115a288f5e848344b1b1e8dccb1c58f1ndtypedef struct {
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung const char *user;
6ae232055d4d8a97267517c5e50074c2c819941and const char *realm;
b43f840409794ed298e8634f6284741f193b6c4ftakashitypedef struct {
b43f840409794ed298e8634f6284741f193b6c4ftakashi const char *label;
b43f840409794ed298e8634f6284741f193b6c4ftakashi const char *query;
6ae232055d4d8a97267517c5e50074c2c819941and/* optional function - look it up once in post_config */
6ae232055d4d8a97267517c5e50074c2c819941andstatic ap_dbd_t *(*authn_dbd_acquire_fn)(request_rec*) = NULL;
6ae232055d4d8a97267517c5e50074c2c819941andstatic void (*authn_dbd_prepare_fn)(server_rec*, const char*, const char*) = NULL;
6ae232055d4d8a97267517c5e50074c2c819941andstatic APR_OPTIONAL_FN_TYPE(ap_authn_cache_store) *authn_cache_store = NULL;
6ae232055d4d8a97267517c5e50074c2c819941andstatic void *authn_dbd_cr_conf(apr_pool_t *pool, char *dummy)
6ae232055d4d8a97267517c5e50074c2c819941and authn_dbd_conf *ret = apr_pcalloc(pool, sizeof(authn_dbd_conf));
6ae232055d4d8a97267517c5e50074c2c819941andstatic void *authn_dbd_merge_conf(apr_pool_t *pool, void *BASE, void *ADD)
6ae232055d4d8a97267517c5e50074c2c819941and authn_dbd_conf *ret = apr_palloc(pool, sizeof(authn_dbd_conf));
6ae232055d4d8a97267517c5e50074c2c819941and ret->user = (add->user == NULL) ? base->user : add->user;
6ae232055d4d8a97267517c5e50074c2c819941and ret->realm = (add->realm == NULL) ? base->realm : add->realm;
6ae232055d4d8a97267517c5e50074c2c819941andstatic const char *authn_dbd_prepare(cmd_parms *cmd, void *cfg, const char *query)
6ae232055d4d8a97267517c5e50074c2c819941and static unsigned int label_num = 0;
6ae232055d4d8a97267517c5e50074c2c819941and authn_dbd_prepare_fn = APR_RETRIEVE_OPTIONAL_FN(ap_dbd_prepare);
6ae232055d4d8a97267517c5e50074c2c819941and return "You must load mod_dbd to enable AuthDBD functions";
6ae232055d4d8a97267517c5e50074c2c819941and authn_dbd_acquire_fn = APR_RETRIEVE_OPTIONAL_FN(ap_dbd_acquire);
6ae232055d4d8a97267517c5e50074c2c819941and label = apr_psprintf(cmd->pool, "authn_dbd_%d", ++label_num);
6ae232055d4d8a97267517c5e50074c2c819941and /* save the label here for our own use */
f4cbda69df0490c6deaacb8d04f103d200ddd183nd "Query used to fetch password for user"),
df4578cbf77fc9e35ccade1f01b137b7eea5ede6nd AP_INIT_TAKE1("AuthDBDUserRealmQuery", authn_dbd_prepare,
f4cbda69df0490c6deaacb8d04f103d200ddd183nd (void *)APR_OFFSETOF(authn_dbd_conf, realm), ACCESS_CONF,
f4cbda69df0490c6deaacb8d04f103d200ddd183nd "Query used to fetch password for user+realm"),
f4cbda69df0490c6deaacb8d04f103d200ddd183ndstatic authn_status authn_dbd_password(request_rec *r, const char *user,
df4578cbf77fc9e35ccade1f01b137b7eea5ede6nd const char *password)
6ae232055d4d8a97267517c5e50074c2c819941and authn_dbd_conf *conf = ap_get_module_config(r->per_dir_config,
6ae232055d4d8a97267517c5e50074c2c819941and "Failed to acquire database connection to look up "
6ae232055d4d8a97267517c5e50074c2c819941and "No AuthDBDUserPWQuery has been specified");
6ae232055d4d8a97267517c5e50074c2c819941and statement = apr_hash_get(dbd->prepared, conf->user, APR_HASH_KEY_STRING);
6ae232055d4d8a97267517c5e50074c2c819941and "A prepared statement could not be found for "
6ae232055d4d8a97267517c5e50074c2c819941and if (apr_dbd_pvselect(dbd->driver, r->pool, dbd->handle, &res, statement,
6ae232055d4d8a97267517c5e50074c2c819941and "Query execution error looking up '%s' "
6ae232055d4d8a97267517c5e50074c2c819941and for (rv = apr_dbd_get_row(dbd->driver, r->pool, res, &row, -1);
6ae232055d4d8a97267517c5e50074c2c819941and rv = apr_dbd_get_row(dbd->driver, r->pool, res, &row, -1)) {
6ae232055d4d8a97267517c5e50074c2c819941and if (rv != 0) {
6ae232055d4d8a97267517c5e50074c2c819941and "Error retrieving results while looking up '%s' "
6ae232055d4d8a97267517c5e50074c2c819941and#if APU_MAJOR_VERSION > 1 || (APU_MAJOR_VERSION == 1 && APU_MINOR_VERSION >= 3)
6ae232055d4d8a97267517c5e50074c2c819941and /* add the rest of the columns to the environment */
6ae232055d4d8a97267517c5e50074c2c819941and int i = 1;
1462ff536f1b939bb337766b2056109c29664c4erbowen const char *name;
1462ff536f1b939bb337766b2056109c29664c4erbowen int j = sizeof(AUTHN_PREFIX)-1; /* string length of "AUTHENTICATE_", excluding the trailing NIL */
1462ff536f1b939bb337766b2056109c29664c4erbowen while (str[j]) {
6ae232055d4d8a97267517c5e50074c2c819941and /* we can't break out here or row won't get cleaned up */
6ae232055d4d8a97267517c5e50074c2c819941andstatic authn_status authn_dbd_realm(request_rec *r, const char *user,
6ae232055d4d8a97267517c5e50074c2c819941and authn_dbd_conf *conf = ap_get_module_config(r->per_dir_config,
6ae232055d4d8a97267517c5e50074c2c819941and "Failed to acquire database connection to look up "
6ae232055d4d8a97267517c5e50074c2c819941and "No AuthDBDUserRealmQuery has been specified");
6ae232055d4d8a97267517c5e50074c2c819941and statement = apr_hash_get(dbd->prepared, conf->realm, APR_HASH_KEY_STRING);
6ae232055d4d8a97267517c5e50074c2c819941and "A prepared statement could not be found for "
6ae232055d4d8a97267517c5e50074c2c819941and if (apr_dbd_pvselect(dbd->driver, r->pool, dbd->handle, &res, statement,
aded39829fe5f862c6c8095f42f7cc38e3407978rbowen "Query execution error looking up '%s:%s' "
aded39829fe5f862c6c8095f42f7cc38e3407978rbowen for (rv = apr_dbd_get_row(dbd->driver, r->pool, res, &row, -1);
aded39829fe5f862c6c8095f42f7cc38e3407978rbowen rv = apr_dbd_get_row(dbd->driver, r->pool, res, &row, -1)) {
aded39829fe5f862c6c8095f42f7cc38e3407978rbowen if (rv != 0) {
6ae232055d4d8a97267517c5e50074c2c819941and "Error retrieving results while looking up '%s:%s' "
6ae232055d4d8a97267517c5e50074c2c819941and#if APU_MAJOR_VERSION > 1 || (APU_MAJOR_VERSION == 1 && APU_MINOR_VERSION >= 3)
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd /* add the rest of the columns to the environment */
727872d18412fc021f03969b8641810d8896820bhumbedooh const char *name;
0d0ba3a410038e179b695446bb149cce6264e0abnd int j = sizeof(AUTHN_PREFIX)-1; /* string length of "AUTHENTICATE_", excluding the trailing NIL */
0d0ba3a410038e179b695446bb149cce6264e0abnd while (str[j]) {
if (!dbd_hash) {
return AUTH_USER_NOT_FOUND;
return AUTH_USER_FOUND;
static void opt_retr(void)
NULL,
NULL,