#ifdef __GNUC__
#ident "$Id: auth_sasldb.c,v 1.1 2004/03/31 18:08:42 dasenbro Exp $"
#endif
#include "mechanisms.h"
#include <string.h>
#include <stdlib.h>
#include <pwd.h>
#define RETURN(x) return strdup(x)
#ifdef AUTH_SASLDB
#include "../include/sasl.h"
#include "../include/saslplug.h"
#include "../sasldb/sasldb.h"
static int
vf(void *context __attribute__((unused)),
char *file __attribute__((unused)),
int type __attribute__((unused)))
{
return SASL_OK;
}
static int lame_getcallback(sasl_conn_t *conn __attribute__((unused)),
unsigned long callbackid,
int (**pproc)(),
void **pcontext)
{
if(callbackid == SASL_CB_VERIFYFILE) {
*pproc = vf;
*pcontext = NULL;
return SASL_OK;
}
return SASL_FAIL;
}
static void lame_log(sasl_conn_t *conn, int level, const char *fmt, ...)
{
return;
}
static void lame_seterror(sasl_conn_t *conn, unsigned flags,
const char *fmt, ...)
{
return;
}
static void init_lame_utils(sasl_utils_t *utils)
{
memset(utils, 0, sizeof(sasl_utils_t));
utils->malloc=(sasl_malloc_t *)malloc;
utils->calloc=(sasl_calloc_t *)calloc;
utils->realloc=(sasl_realloc_t *)realloc;
utils->free=(sasl_free_t *)free;
utils->getcallback=lame_getcallback;
utils->log=lame_log;
utils->seterror=lame_seterror;
return;
}
#endif
char *
auth_sasldb (
#ifdef AUTH_SASLDB
const char *login,
const char *password,
const char *service __attribute__((unused)),
const char *realm
#else
const char *login __attribute__((unused)),
const char *password __attribute__((unused)),
const char *service __attribute__((unused)),
const char *realm __attribute__((unused))
#endif
)
{
#ifdef AUTH_SASLDB
char pw[1024];
sasl_utils_t utils;
int ret, outsize;
const char *use_realm;
char realm_buf[MAXHOSTNAMELEN];
init_lame_utils(&utils);
_sasl_check_db(&utils, (void *)0x1);
if(!realm || !strlen(realm)) {
ret = gethostname(realm_buf,MAXHOSTNAMELEN);
if(ret) RETURN("NO");
use_realm = realm_buf;
} else {
use_realm = realm;
}
ret = _sasldb_getdata(&utils, (void *)0x1, login, use_realm,
"userPassword", pw, 1024, &outsize);
if (ret != SASL_OK) {
RETURN("NO");
}
if (strcmp(pw, password)) {
RETURN("NO");
}
RETURN("OK");
#else
RETURN("NO");
#endif
}