mech.c revision 5fb63932ddaa3a4043e33ccd5b2d50037448535f
/* Copyright (C) 2002 Timo Sirainen */
#include "common.h"
#include "ioloop.h"
#include "buffer.h"
#include "hash.h"
#include "mech.h"
#include "safe-memset.h"
#include "str.h"
#include "str-sanitize.h"
#include "var-expand.h"
#include "auth-client-connection.h"
#include "auth-master-connection.h"
#include "passdb.h"
#include "passdb-cache.h"
#include <stdlib.h>
struct auth_request_extra {
struct auth_request *request;
char *user_password, *password;
};
struct mech_module_list *mech_modules;
const char *const *auth_realms;
const char *default_realm;
const char *anonymous_username;
static buffer_t *auth_failures_buf;
static struct timeout *to_auth_failures;
{
struct mech_module_list *list;
mech_modules = list;
}
{
break;
}
}
}
const string_t *auth_mechanisms_get_list(void)
{
struct mech_module_list *list;
return str;
}
{
struct mech_module_list *list;
}
return NULL;
}
{
struct auth_request *request;
return NULL;
return request;
}
{
}
}
{
if (!success) {
if (request->no_failure_delay) {
/* passdb specifically requested to to delay the
reply. */
NULL, 0);
return;
}
/* failure. don't announce it immediately to avoid
a) timing attacks, b) flooding */
if (auth_failures_buf->used > 0) {
const struct auth_request *const *requests;
}
return;
}
}
/* we don't have master process, the request is no longer
needed */
}
}
{
unsigned char *p;
if (*username == '\0') {
/* Some PAM plugins go nuts with empty usernames */
*error_r = "Empty username";
return FALSE;
}
for (p = (unsigned char *)username; *p != '\0'; p++) {
if (username_translation[*p & 0xff] != 0)
*p = username_translation[*p & 0xff];
if (username_chars[*p & 0xff] == 0) {
*error_r = "Username contains disallowed characters";
return FALSE;
}
}
return TRUE;
}
{
}
{
return TRUE;
return FALSE;
}
struct auth_request_extra *
const char *user_password)
{
struct auth_request_extra *extra;
return extra;
}
{
return;
}
/* don't delay replying to client of the failure */
return;
}
/* user can't actually login - don't keep this
reply for master */
/* we're proxying authentication for this user. send
password back if using plaintext authentication. */
} else {
}
}
const char *cache_key)
{
}
}
/* we're proxying - send back the password that was
sent by user (not the password in passdb). */
}
}
}
}
static const char *escape_none(const char *str)
{
return str;
}
const struct var_expand_table *
const char *(*escape_func)(const char *))
{
static struct var_expand_table static_tab[] = {
{ 'u', NULL },
{ 'n', NULL },
{ 'd', NULL },
{ 's', NULL },
{ 'h', NULL },
{ 'l', NULL },
{ 'r', NULL },
{ 'p', NULL },
{ '\0', NULL }
};
struct var_expand_table *tab;
if (escape_func == NULL)
/* tab[4] = we have no home dir */
return tab;
}
{
#define MAX_LOG_USERNAME_LEN 64
const char *ip;
else {
}
}
}
void auth_failure_buf_flush(void)
{
struct auth_request **auth_request;
size /= sizeof(*auth_request);
for (i = 0; i < size; i++) {
NULL, 0);
}
}
}
{
}
{
struct mech_module_list *list;
break;
break;
}
i_fatal("Passdb %s doesn't support %s method",
}
}
extern struct mech_module mech_plain;
extern struct mech_module mech_login;
extern struct mech_module mech_apop;
extern struct mech_module mech_cram_md5;
extern struct mech_module mech_digest_md5;
extern struct mech_module mech_ntlm;
extern struct mech_module mech_rpa;
extern struct mech_module mech_anonymous;
void mech_init(void)
{
const char *const *mechanisms;
const char *env;
mech_modules = NULL;
/* register wanted mechanisms */
i_fatal("MECHANISMS environment is unset");
while (*mechanisms != NULL) {
if (anonymous_username == NULL) {
i_fatal("ANONYMOUS listed in mechanisms, "
"but anonymous_username not given");
}
} else {
i_fatal("Unknown authentication mechanism '%s'",
*mechanisms);
}
mechanisms++;
}
if (mech_modules == NULL)
i_fatal("No authentication mechanisms configured");
/* get our realm - note that we allocate from data stack so
this function should never be called inside I/O loop or anywhere
else where t_pop() is called */
env = "";
/* all chars are allowed */
} else {
}
env[1];
}
}
}
void mech_deinit(void)
{
}