1/* MODULE: auth_ldap */
2/* COPYRIGHT
3 * Copyright (c) 2002-2002 Igor Brezac
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY IGOR BREZAC. ``AS IS'' AND ANY
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL IGOR BREZAC OR
19 * ITS EMPLOYEES OR AGENTS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
24 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
25 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
26 * DAMAGE.
27 * END COPYRIGHT */
28
29/* SYNOPSIS
30 * Authenticate against LDAP.
31 * END SYNOPSIS */
32
33#ifdef __GNUC__
34#ident "$Id: auth_ldap.c,v 1.8 2006/01/24 00:16:03 snsimon Exp $"
35#endif
36
37/* PUBLIC DEPENDENCIES */
38#include <stdlib.h>
39#include <string.h>
40#include <syslog.h>
41#include <ctype.h>
42#include "mechanisms.h"
43
44/* END PUBLIC DEPENDENCIES */
45
46# define RETURN(x) {return strdup(x);}
47
48/* FUNCTION: auth_ldap */
49
50#ifdef AUTH_LDAP
51
52#include "lak.h"
53#include "globals.h"
54
55const char *SASLAUTHD_CONF_FILE = SASLAUTHD_CONF_FILE_DEFAULT;
56
57char *					/* R: allocated response string */
58auth_ldap(
59  /* PARAMETERS */
60  const char *login,			/* I: plaintext authenticator */
61  const char *password,			/* I: plaintext password */
62  const char *service,
63  const char *realm
64  /* END PARAMETERS */
65  )
66{
67	static LAK *lak = NULL;
68	int rc = 0;
69
70	if (lak == NULL) {
71		rc = lak_init(SASLAUTHD_CONF_FILE, &lak);
72		if (rc != LAK_OK) {
73			lak = NULL;
74			RETURN("NO");
75		}
76	}
77
78	rc = lak_authenticate(lak, login, service, realm, password);
79    	if (rc == LAK_OK) {
80		RETURN("OK");
81	} else {
82		RETURN("NO");
83	}
84}
85
86/* FUNCTION: auth_ldap_init */
87
88/* SYNOPSIS
89 * Validate the host and service names for the remote server.
90 * END SYNOPSIS */
91
92int
93auth_ldap_init (
94  /* PARAMETERS */
95  void					/* no parameters */
96  /* END PARAMETERS */
97  )
98{
99    /* VARIABLES */
100    struct addrinfo hints;
101    int err;
102    char *c;				/* scratch pointer               */
103    /* END VARIABLES */
104
105    if (mech_option != NULL) {
106	SASLAUTHD_CONF_FILE = mech_option;
107    }
108
109    return 0;
110}
111
112#else /* !AUTH_LDAP */
113
114char *
115auth_ldap(
116  const char *login __attribute__((unused)),
117  const char *password __attribute__((unused)),
118  const char *service __attribute__((unused)),
119  const char *realm __attribute__((unused))
120  )
121{
122     return NULL;
123}
124
125#endif /* !AUTH_LDAP */
126
127/* END FUNCTION: auth_ldap */
128
129/* END MODULE: auth_ldap */
130