1 /* MODULE: auth_sasldb */
4 * Copyright (c) 1997-2000 Messaging Direct Ltd.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY MESSAGING DIRECT LTD. ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MESSAGING DIRECT LTD. OR
20 * ITS EMPLOYEES OR AGENTS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
23 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
25 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
26 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
31 * crypt(3) based passwd file validation
35 #ident "$Id: auth_sasldb.c,v 1.5 2002/07/27 18:44:46 rjs3 Exp $"
38 /* PUBLIC DEPENDENCIES */
39 #include "mechanisms.h"
44 /* END PUBLIC DEPENDENCIES */
46 #define RETURN(x) return strdup(x)
50 #include "../include/sasl.h"
51 #include "../include/saslplug.h"
52 #include "../sasldb/sasldb.h"
55 vf(void *context __attribute__((unused)),
56 char *file __attribute__((unused)),
57 int type __attribute__((unused)))
63 static int lame_getcallback(sasl_conn_t *conn __attribute__((unused)),
64 unsigned long callbackid,
68 if(callbackid == SASL_CB_VERIFYFILE) {
77 static void lame_log(sasl_conn_t *conn, int level, const char *fmt, ...)
82 static void lame_seterror(sasl_conn_t *conn, unsigned flags,
88 /* FUNCTION: init_lame_utils */
89 /* This sets up a very minimal sasl_utils_t for use only with the
90 * database functions */
91 static void init_lame_utils(sasl_utils_t *utils)
93 memset(utils, 0, sizeof(sasl_utils_t));
95 utils->malloc=(sasl_malloc_t *)malloc;
96 utils->calloc=(sasl_calloc_t *)calloc;
97 utils->realloc=(sasl_realloc_t *)realloc;
98 utils->free=(sasl_free_t *)free;
100 utils->getcallback=lame_getcallback;
102 utils->seterror=lame_seterror;
107 /* END FUNCTION: init_lame_utils */
109 #endif /* AUTH_SASLDB */
111 /* FUNCTION: auth_sasldb */
113 char * /* R: allocated response string */
117 const char *login, /* I: plaintext authenticator */
118 const char *password, /* I: plaintext password */
119 const char *service __attribute__((unused)),
122 const char *login __attribute__((unused)),/* I: plaintext authenticator */
123 const char *password __attribute__((unused)), /* I: plaintext password */
124 const char *service __attribute__((unused)),
125 const char *realm __attribute__((unused))
132 char pw[1024]; /* pointer to passwd file entry */
135 const char *use_realm;
136 char realm_buf[MAXHOSTNAMELEN];
139 init_lame_utils(&utils);
141 _sasl_check_db(&utils, (void *)0x1);
143 if(!realm || !strlen(realm)) {
144 ret = gethostname(realm_buf,MAXHOSTNAMELEN);
145 if(ret) RETURN("NO");
146 use_realm = realm_buf;
152 ret = _sasldb_getdata(&utils, (void *)0x1, login, use_realm,
153 "userPassword", pw, 1024, &outsize);
155 if (ret != SASL_OK) {
159 if (strcmp(pw, password)) {
169 /* END FUNCTION: auth_sasldb */
171 /* END MODULE: auth_sasldb */