mech.c revision 6d701b8abc45d6d3881ee19ffc6f38b23d35eea5
/* Copyright (C) 2002 Timo Sirainen */
#include "common.h"
#include "ioloop.h"
#include "buffer.h"
#include "hash.h"
#include "mech.h"
#include "var-expand.h"
#include "auth-client-connection.h"
#include "auth-master-connection.h"
#include <stdlib.h>
struct mech_module_list {
struct mech_module_list *next;
struct mech_module module;
};
enum auth_mech auth_mechanisms;
const char *const *auth_realms;
const char *default_realm;
const char *anonymous_username;
char username_chars[256];
static int set_use_cyrus_sasl;
static int ssl_require_client_cert;
static struct mech_module_list *mech_modules;
static struct auth_client_request_reply failure_reply;
{
struct mech_module_list *list;
mech_modules = list;
}
{
return; /* not registered */
break;
}
}
}
struct auth_client_request_new *request,
{
struct mech_module_list *list;
struct auth_request *auth_request;
/* unsupported mechanism */
i_error("BUG: Auth client %u requested unsupported "
return;
}
if (ssl_require_client_cert &&
/* we fail without valid certificate */
if (verbose)
i_info("Client didn't present valid SSL certificate");
return;
}
#ifdef USE_CYRUS_SASL2
if (set_use_cyrus_sasl) {
} else
#endif
{
auth_request = NULL;
callback);
break;
}
}
}
if (auth_request != NULL) {
sizeof(auth_request->protocol));
}
}
struct auth_client_request_continue *request,
const unsigned char *data,
{
struct auth_request *auth_request;
if (auth_request == NULL) {
/* timeouted */
} else {
}
}
{
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;
if (success) {
} else {
reply_data = NULL;
}
/* request is no longer needed, either because the
authentication failed or because we don't have master
process */
}
}
int mech_is_valid_username(const char *username)
{
const unsigned char *p;
for (p = (const unsigned char *)username; *p != '\0'; p++) {
if (username_chars[*p & 0xff] == 0)
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 },
{ '\0', NULL }
};
struct var_expand_table *tab;
if (escape_func == NULL)
return tab;
}
extern struct mech_module mech_plain;
extern struct mech_module mech_cram_md5;
extern struct mech_module mech_digest_md5;
extern struct mech_module mech_anonymous;
void mech_init(void)
{
const char *const *mechanisms;
const char *env;
mech_modules = NULL;
auth_mechanisms = 0;
/* 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 (auth_mechanisms == 0)
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 {
}
#ifdef USE_CYRUS_SASL2
if (set_use_cyrus_sasl)
#endif
}
void mech_deinit(void)
{
}