mod_authz_dbd.c revision f6098228fada9d4d6dcdc0cd321f4f5904040d1e
97a9a944b5887e91042b019776c41d5dd74557aferikabele/* Licensed to the Apache Software Foundation (ASF) under one or more
97a9a944b5887e91042b019776c41d5dd74557aferikabele * 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
a945f35eff8b6a88009ce73de6d4c862ce58de3cslive * the License. You may obtain a copy of the License at
96ad5d81ee4a2cc66a4ae19893efc8aa6d06fae7jailletc * Unless required by applicable law or agreed to in writing, software
b686b6a420bde7f78c416b90be11db94cb789979nd * distributed under the License is distributed on an "AS IS" BASIS,
b686b6a420bde7f78c416b90be11db94cb789979nd * 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.
b686b6a420bde7f78c416b90be11db94cb789979nd/* Export a hook for modules that manage clientside sessions
b686b6a420bde7f78c416b90be11db94cb789979nd * (e.g. mod_auth_cookie)
b686b6a420bde7f78c416b90be11db94cb789979nd * to deal with those when we successfully login/logout at the server
b686b6a420bde7f78c416b90be11db94cb789979nd * XXX: WHY would this be specific to dbd_authz? Why wouldn't we track
06ba4a61654b3763ad65f52283832ebf058fdf1cslive * this across all authz user providers in a lower level mod, such as
b0f39810a93af064583df3741ae61d5351934b62ndAPR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(authz_dbd, AUTHZ_DBD, int, client_login,
06ba4a61654b3763ad65f52283832ebf058fdf1cslivetypedef struct {
b0f39810a93af064583df3741ae61d5351934b62nd const char *query;
b0f39810a93af064583df3741ae61d5351934b62nd const char *redir_query;
06ba4a61654b3763ad65f52283832ebf058fdf1cslivestatic void (*dbd_prepare)(server_rec*, const char*, const char*) = NULL;
06ba4a61654b3763ad65f52283832ebf058fdf1cslivestatic void *authz_dbd_cr_cfg(apr_pool_t *pool, char *dummy)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive authz_dbd_cfg *ret = apr_pcalloc(pool, sizeof(authz_dbd_cfg));
b686b6a420bde7f78c416b90be11db94cb789979ndstatic void *authz_dbd_merge_cfg(apr_pool_t *pool, void *BASE, void *ADD)
c44eeebd065e2c8cd028016b45c58afb480aaf8fdruggeri authz_dbd_cfg *ret = apr_palloc(pool, sizeof(authz_dbd_cfg));
b686b6a420bde7f78c416b90be11db94cb789979nd ret->query = (add->query == NULL) ? base->query : add->query;
c44eeebd065e2c8cd028016b45c58afb480aaf8fdruggeri ret->redirect = (add->redirect == -1) ? base->redirect : add->redirect;
b686b6a420bde7f78c416b90be11db94cb789979ndstatic const char *authz_dbd_prepare(cmd_parms *cmd, void *cfg,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive const char *query)
b0f39810a93af064583df3741ae61d5351934b62nd static unsigned int label_num = 0;
0cf3cdbaa1dad11cbf1ce32e48f1b4ec88cf779fnilgun const char *err = ap_check_cmd_context(cmd, NOT_IN_HTACCESS);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive dbd_prepare = APR_RETRIEVE_OPTIONAL_FN(ap_dbd_prepare);
b0f39810a93af064583df3741ae61d5351934b62nd return "You must load mod_dbd to enable AuthzDBD functions";
b0f39810a93af064583df3741ae61d5351934b62nd label = apr_psprintf(cmd->pool, "authz_dbd_%d", ++label_num);
b0f39810a93af064583df3741ae61d5351934b62nd /* save the label here for our own use */
b0f39810a93af064583df3741ae61d5351934b62nd (void*)APR_OFFSETOF(authz_dbd_cfg, redirect), ACCESS_CONF,
b0f39810a93af064583df3741ae61d5351934b62nd "Whether to redirect to referer on successful login"),
b0f39810a93af064583df3741ae61d5351934b62nd "SQL query for DBD Authz or login"),
b0f39810a93af064583df3741ae61d5351934b62nd AP_INIT_TAKE1("AuthzDBDRedirectQuery", authz_dbd_prepare,
b0f39810a93af064583df3741ae61d5351934b62nd (void*)APR_OFFSETOF(authz_dbd_cfg, redir_query), ACCESS_CONF,
b0f39810a93af064583df3741ae61d5351934b62nd "SQL query to get per-user redirect URL after login"),
b0f39810a93af064583df3741ae61d5351934b62ndstatic int authz_dbd_login(request_rec *r, authz_dbd_cfg *cfg,
b0f39810a93af064583df3741ae61d5351934b62nd const char *action)
b0f39810a93af064583df3741ae61d5351934b62nd const char *message;
b0f39810a93af064583df3741ae61d5351934b62nd ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01642)
b0f39810a93af064583df3741ae61d5351934b62nd query = apr_hash_get(dbd->prepared, cfg->query, APR_HASH_KEY_STRING);
b0f39810a93af064583df3741ae61d5351934b62nd ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01643)
b0f39810a93af064583df3741ae61d5351934b62nd rv = apr_dbd_pvquery(dbd->driver, r->pool, dbd->handle, &nrows,
4db087c26379b76fb2cce36137cbdc112824777and if (rv == 0) {
b0f39810a93af064583df3741ae61d5351934b62nd ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, APLOGNO(01644)
b0f39810a93af064583df3741ae61d5351934b62nd "authz_dbd: %s of user %s updated %d rows",
b0f39810a93af064583df3741ae61d5351934b62nd ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01645)
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar "authz_dbd: query for %s failed; user %s [%s]",
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01646)
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar "authz_dbd: no redirect query!");
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar /* OK, this is non-critical; we can just not-redirect */
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar else if ((rv = apr_dbd_pvselect(dbd->driver, r->pool, dbd->handle,
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar for (rv = apr_dbd_get_row(dbd->driver, r->pool, res, &row, -1);
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar rv = apr_dbd_get_row(dbd->driver, r->pool, res, &row, -1)) {
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar if (rv != 0) {
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01647)
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar "authz_dbd in get_row; action=%s user=%s [%s]",
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar /* we can't break out here or row won't get cleaned up */
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01648)
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar "authz_dbd/redirect for %s of %s [%s]",
1f1b6bf13313fdd14a45e52e553d3ff28689b717coarstatic int authz_dbd_group_query(request_rec *r, authz_dbd_cfg *cfg,
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar /* SELECT group FROM authz WHERE user = %s */
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar const char *message;
b686b6a420bde7f78c416b90be11db94cb789979nd const char **group;
07dc96d063d49299da433f84b5c5681da9bbdf68rbowen ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01649)
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung "No query configured for dbd-group!");
727872d18412fc021f03969b8641810d8896820bhumbedooh query = apr_hash_get(dbd->prepared, cfg->query, APR_HASH_KEY_STRING);
0d0ba3a410038e179b695446bb149cce6264e0abnd ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01650)
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedooh "Error retrieving query for dbd-group!");
0d0ba3a410038e179b695446bb149cce6264e0abnd rv = apr_dbd_pvselect(dbd->driver, r->pool, dbd->handle, &res,
ac082aefa89416cbdc9a1836eaf3bed9698201c8humbedooh if (rv == 0) {
0d0ba3a410038e179b695446bb149cce6264e0abnd for (rv = apr_dbd_get_row(dbd->driver, r->pool, res, &row, -1);
0d0ba3a410038e179b695446bb149cce6264e0abnd rv = apr_dbd_get_row(dbd->driver, r->pool, res, &row, -1)) {
727872d18412fc021f03969b8641810d8896820bhumbedooh if (rv == 0) {
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen message = apr_dbd_error(dbd->driver, dbd->handle, rv);
0d0ba3a410038e179b695446bb149cce6264e0abnd ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01651)
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd "authz_dbd in get_row; group query for user=%s [%s]",
return HTTP_INTERNAL_SERVER_ERROR;
return OK;
const char *require_args,
const void *parsed_require_args)
int i, rv;
const char *require;
if (!r->user) {
return AUTHZ_DENIED_NO_USER;
return AUTHZ_GENERAL_ERROR;
if (err) {
return AUTHZ_DENIED;
t = require;
return AUTHZ_GRANTED;
return AUTHZ_DENIED;
const char *require_args,
const void *parsed_require_args)
if (!r->user) {
return AUTHZ_DENIED_NO_USER;
const char *require_args,
const void *parsed_require_args)
if (!r->user) {
return AUTHZ_DENIED_NO_USER;
const void **parsed_require_line)
if (expr_err)
return NULL;
NULL,
NULL,
NULL,
NULL,