mod_auth_basic.c revision 78cd48acd325773619d78ac0d7263a99a8922fae
/* Copyright 2002-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "apr_strings.h"
#include "apr_md5.h" /* for apr_password_validate */
#include "apr_lib.h" /* for apr_isspace */
#include "apr_base64.h" /* for apr_base64_decode et al */
#define APR_WANT_STRFUNC /* for strcasecmp */
#include "apr_want.h"
#include "ap_config.h"
#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_log.h"
#include "http_protocol.h"
#include "http_request.h"
#include "ap_provider.h"
#include "mod_auth.h"
typedef struct {
char *dir;
int authoritative;
static void *create_auth_basic_dir_config(apr_pool_t *p, char *d)
{
/* Any failures are fatal. */
return conf;
}
const char *arg)
{
const char *provider_name;
}
/* Clear all configured providers and return. */
return NULL;
}
else {
}
/* lookup and cache the actual provider now */
/* by the time they use it, the provider should be loaded and
registered with us. */
"Unknown Authn provider: %s",
}
/* if it doesn't provide the appropriate function, reject it */
"The '%s' Authn provider doesn't support "
"Basic Authentication", provider_name);
}
/* Add it to the list now. */
}
else {
}
}
return NULL;
}
static const command_rec auth_basic_cmds[] =
{
"specify the auth providers for a directory or location"),
"Set to 'Off' to allow access control to be passed along to "
"lower modules if the UserID is not known to this module"),
{NULL}
};
/* These functions return 0 if client is OK, and proper error status
* if not... either HTTP_UNAUTHORIZED, if we made a check, and it failed, or
* HTTP_INTERNAL_SERVER_ERROR, if things are so totally confused that we
* couldn't figure out how to tell if the client is authorized or not.
*
* If they return DECLINED, and all other modules also decline, that's
* treated by the server core as a configuration error, logged and
* reported as such.
*/
static void note_basic_auth_failure(request_rec *r)
{
: "WWW-Authenticate",
"\"", NULL));
}
const char **pw)
{
const char *auth_line;
char *decoded_line;
int length;
/* Get the appropriate header */
? "Proxy-Authorization"
: "Authorization");
if (!auth_line) {
return HTTP_UNAUTHORIZED;
}
/* Client tried to authenticate using wrong auth scheme */
"client used wrong authentication scheme: %s", r->uri);
return HTTP_UNAUTHORIZED;
}
/* Skip leading spaces. */
while (apr_isspace(*auth_line)) {
auth_line++;
}
/* Null-terminate the string. */
*pw = decoded_line;
return OK;
}
/* Determine user ID, and check if it really is that user, for HTTP
* basic authentication...
*/
static int authenticate_basic_user(request_rec *r)
{
int res;
/* Are we configured to be Basic auth? */
current_auth = ap_auth_type(r);
return DECLINED;
}
/* We need an authentication realm. */
if (!ap_auth_name(r)) {
0, r, "need AuthName: %s", r->uri);
return HTTP_INTERNAL_SERVER_ERROR;
}
r->ap_auth_type = "Basic";
if (res) {
return res;
}
do {
const authn_provider *provider;
/* For now, if a provider isn't set, we'll be nice and use the file
* provider.
*/
if (!current_provider) {
AUTHN_DEFAULT_PROVIDER, "0");
"No Authn provider configured");
break;
}
}
else {
}
/* Something occured. Stop checking. */
if (auth_result != AUTH_USER_NOT_FOUND) {
break;
}
/* If we're not really configured for providers, stop now. */
break;
}
} while (current_provider);
if (auth_result != AUTH_GRANTED) {
int return_code;
/* If we're not authoritative, then any error is ignored. */
return DECLINED;
}
switch (auth_result) {
case AUTH_DENIED:
"user %s: authentication failure for \"%s\": "
"Password Mismatch",
break;
case AUTH_USER_NOT_FOUND:
break;
case AUTH_GENERAL_ERROR:
default:
/* We'll assume that the module has already said what its error
* was in the logs.
*/
break;
}
/* If we're returning 403, tell them to try again. */
if (return_code == HTTP_UNAUTHORIZED) {
}
return return_code;
}
/* Now that we are done, set the request_rec values so others will know
* who we are.
*/
r->ap_auth_type = "Basic";
return OK;
}
static void register_hooks(apr_pool_t *p)
{
}
{
create_auth_basic_dir_config, /* dir config creater */
NULL, /* dir merger --- default is to override */
NULL, /* server config */
NULL, /* merge server config */
auth_basic_cmds, /* command apr_table_t */
register_hooks /* register hooks */
};