mech.c revision 7eb7d277e4299087734a912e9696dea51a151f43
/* Copyright (C) 2002 Timo Sirainen */
#include "common.h"
#include "ioloop.h"
#include "buffer.h"
#include "hash.h"
#include "mech.h"
#include "str.h"
#include "var-expand.h"
#include "auth-client-connection.h"
#include "auth-master-connection.h"
#include <stdlib.h>
struct mech_module_list *mech_modules;
const char *const *auth_realms;
const char *default_realm;
const char *anonymous_username;
static int set_use_cyrus_sasl;
static struct auth_client_request_reply failure_reply;
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_client_request_new *request,
const unsigned char *data,
{
struct mech_module *mech;
struct auth_request *auth_request;
ip_size = 4;
else
ip_size = 0;
/* make sure data is NUL-terminated */
i_error("BUG: Auth client %u sent corrupted request",
return;
}
/* unsupported mechanism */
i_error("BUG: Auth client %u requested unsupported "
return;
}
#ifdef USE_CYRUS_SASL2
if (set_use_cyrus_sasl)
else
#endif
if (auth_request == NULL)
return;
}
if (ssl_require_client_cert &&
/* we fail without valid certificate */
if (verbose) {
i_info("ssl-cert-check(%s): "
"Client didn't present valid SSL certificate",
}
return;
}
}
struct auth_client_request_continue *request,
const unsigned char *data,
{
struct auth_request *auth_request;
if (auth_request == NULL) {
/* timeouted */
} else {
callback))
}
}
{
POINTER_CAST(id));
}
}
{
}
struct auth_request *auth_request,
{
reply->username_idx = 0;
if (data_size == 0)
else {
}
}
{
struct auth_client_request_reply reply;
void *reply_data;
int free_request;
if (!success) {
/* failure. don't announce it immediately to avoid
a) timing attacks, b) flooding */
&auth_request, sizeof(auth_request));
return;
}
/* get this before callback because it can destroy connection */
if (free_request) {
/* 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;
}
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 },
{ 'p', 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 *p, *ip;
else {
/* any control characters in username will be replaced by '?' */
if ((unsigned char)*p < 32)
break;
}
for (; *p != '\0'; p++) {
if ((unsigned char)*p < 32)
else
str_append_c(str, *p);
}
}
}
}
}
void auth_failure_buf_flush(void)
{
struct auth_request **auth_request;
struct auth_client_request_reply reply;
size /= sizeof(*auth_request);
for (i = 0; i < size; i++) {
}
}
{
}
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];
}
}
#ifdef USE_CYRUS_SASL2
if (set_use_cyrus_sasl)
#endif
}
void mech_deinit(void)
{
}