1
/* Licensed to the Apache Software Foundation (ASF) under one or more
2
* contributor license agreements. See the NOTICE file distributed with
3
* this work for additional information regarding copyright ownership.
4
* The ASF licenses this file to You under the Apache License, Version 2.0
5
* (the "License"); you may not use this file except in compliance with
6
* the License. You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
18
* http_auth: authentication
20
* Rob McCool & Brian Behlendorf.
22
* Adapted to Apache by rst.
26
#define APR_WANT_STRFUNC
28
#include "apr_strings.h"
30
#include "apr_md5.h" /* for apr_password_validate */
32
#include "ap_provider.h"
34
#include "http_config.h"
35
#include "http_core.h"
37
#include "http_protocol.h"
38
#include "http_request.h" /* for ap_hook_(check_user_id | auth_checker)*/
45
} authn_dbm_config_rec;
47
static void *create_authn_dbm_dir_config(apr_pool_t *p, char *d)
49
authn_dbm_config_rec *conf = apr_palloc(p, sizeof(*conf));
52
conf->dbmtype = "default";
57
static const char *set_dbm_type(cmd_parms *cmd,
61
authn_dbm_config_rec *conf = dir_config;
63
conf->dbmtype = apr_pstrdup(cmd->pool, arg);
67
static const command_rec authn_dbm_cmds[] =
69
AP_INIT_TAKE1("AuthDBMUserFile", ap_set_file_slot,
70
(void *)APR_OFFSETOF(authn_dbm_config_rec, pwfile),
71
OR_AUTHCFG, "dbm database file containing user IDs and passwords"),
72
AP_INIT_TAKE1("AuthDBMType", set_dbm_type,
74
OR_AUTHCFG, "what type of DBM file the user file is"),
78
module AP_MODULE_DECLARE_DATA authn_dbm_module;
80
static apr_status_t fetch_dbm_value(const char *dbmtype, const char *dbmfile,
81
const char *user, char **value,
88
rv = apr_dbm_open_ex(&f, dbmtype, dbmfile, APR_DBM_READONLY,
89
APR_OS_DEFAULT, pool);
91
if (rv != APR_SUCCESS) {
95
key.dptr = (char*)user;
96
#ifndef NETSCAPE_DBM_COMPAT
97
key.dsize = strlen(key.dptr);
99
key.dsize = strlen(key.dptr) + 1;
104
if (apr_dbm_fetch(f, key, &val) == APR_SUCCESS && val.dptr) {
105
*value = apr_pstrmemdup(pool, val.dptr, val.dsize);
113
static authn_status check_dbm_pw(request_rec *r, const char *user,
114
const char *password)
116
authn_dbm_config_rec *conf = ap_get_module_config(r->per_dir_config,
122
rv = fetch_dbm_value(conf->dbmtype, conf->pwfile, user, &dbm_password,
125
if (rv != APR_SUCCESS) {
126
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
127
"could not open dbm (type %s) auth file: %s",
128
conf->dbmtype, conf->pwfile);
129
return AUTH_GENERAL_ERROR;
133
return AUTH_USER_NOT_FOUND;
136
colon_pw = ap_strchr(dbm_password, ':');
141
rv = apr_password_validate(password, dbm_password);
143
if (rv != APR_SUCCESS) {
150
static authn_status get_dbm_realm_hash(request_rec *r, const char *user,
151
const char *realm, char **rethash)
153
authn_dbm_config_rec *conf = ap_get_module_config(r->per_dir_config,
159
rv = fetch_dbm_value(conf->dbmtype, conf->pwfile,
160
apr_pstrcat(r->pool, user, ":", realm, NULL),
163
if (rv != APR_SUCCESS) {
164
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
165
"Could not open dbm (type %s) hash file: %s",
166
conf->dbmtype, conf->pwfile);
167
return AUTH_GENERAL_ERROR;
171
return AUTH_USER_NOT_FOUND;
174
colon_hash = ap_strchr(dbm_hash, ':');
181
return AUTH_USER_FOUND;
184
static const authn_provider authn_dbm_provider =
190
static void register_hooks(apr_pool_t *p)
192
ap_register_provider(p, AUTHN_PROVIDER_GROUP, "dbm", "0",
193
&authn_dbm_provider);
196
module AP_MODULE_DECLARE_DATA authn_dbm_module =
198
STANDARD20_MODULE_STUFF,
199
create_authn_dbm_dir_config, /* dir config creater */
200
NULL, /* dir merger --- default is to override */
201
NULL, /* server config */
202
NULL, /* merge server config */
203
authn_dbm_cmds, /* command apr_table_t */
204
register_hooks /* register hooks */