Remove building with NOCRYPTO option
[minix.git] / external / bsd / dhcp / dist / server / ldap_casa.c
blobcaa0fe7656a65e67d19ff2d43e8363ee992a2283
1 /* $NetBSD: ldap_casa.c,v 1.1.1.3 2014/07/12 11:58:13 spz Exp $ */
2 /* ldap_casa.c
4 CASA routines for DHCPD... */
6 /* Copyright (c) 2006 Novell, Inc.
8 * All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 * 1.Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 * 2.Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 * 3.Neither the name of ISC, ISC DHCP, nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY INTERNET SYSTEMS CONSORTIUM AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ISC OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
32 * This file was written by S Kalyanasundaram <skalyanasundaram@novell.com>
36 * Copyright (c) 2004-2010 by Internet Systems Consortium, Inc. ("ISC")
37 * Copyright (c) 1995-2003 by Internet Software Consortium
39 * Permission to use, copy, modify, and distribute this software for any
40 * purpose with or without fee is hereby granted, provided that the above
41 * copyright notice and this permission notice appear in all copies.
43 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
44 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
45 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
46 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
47 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
48 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
49 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
51 * Internet Systems Consortium, Inc.
52 * 950 Charter Street
53 * Redwood City, CA 94063
54 * <info@isc.org>
55 * https://www.isc.org/
58 #include <sys/cdefs.h>
59 __RCSID("$NetBSD: ldap_casa.c,v 1.1.1.3 2014/07/12 11:58:13 spz Exp $");
61 #if defined(LDAP_CASA_AUTH)
62 #include "ldap_casa.h"
63 #include "dhcpd.h"
65 int
66 load_casa (void)
68 if( !(casaIDK = dlopen(MICASA_LIB,RTLD_LAZY)))
69 return 0;
70 p_miCASAGetCredential = (CASA_GetCredential_T) dlsym(casaIDK, "miCASAGetCredential");
71 p_miCASASetCredential = (CASA_SetCredential_T) dlsym(casaIDK, "miCASASetCredential");
72 p_miCASARemoveCredential = (CASA_RemoveCredential_T) dlsym(casaIDK, "miCASARemoveCredential");
74 if((p_miCASAGetCredential == NULL) ||
75 (p_miCASASetCredential == NULL) ||
76 (p_miCASARemoveCredential == NULL))
78 if(casaIDK)
79 dlclose(casaIDK);
80 casaIDK = NULL;
81 p_miCASAGetCredential = NULL;
82 p_miCASASetCredential = NULL;
83 p_miCASARemoveCredential = NULL;
84 return 0;
86 else
87 return 1;
90 static void
91 release_casa(void)
93 if(casaIDK)
95 dlclose(casaIDK);
96 casaIDK = NULL;
99 p_miCASAGetCredential = NULL;
100 p_miCASASetCredential = NULL;
101 p_miCASARemoveCredential = NULL;
106 load_uname_pwd_from_miCASA (char **ldap_username, char **ldap_password)
108 int result = 0;
109 uint32_t credentialtype = SSCS_CRED_TYPE_SERVER_F;
110 SSCS_BASIC_CREDENTIAL credential;
111 SSCS_SECRET_ID_T applicationSecretId;
112 char *tempVar = NULL;
114 const char applicationName[10] = "dhcp-ldap";
116 if ( load_casa() )
118 memset(&credential, 0, sizeof(SSCS_BASIC_CREDENTIAL));
119 memset(&applicationSecretId, 0, sizeof(SSCS_SECRET_ID_T));
121 applicationSecretId.len = strlen(applicationName) + 1;
122 memcpy (applicationSecretId.id, applicationName, applicationSecretId.len);
124 credential.unFlags = USERNAME_TYPE_CN_F;
126 result = p_miCASAGetCredential (0,
127 &applicationSecretId,NULL,&credentialtype,
128 &credential,NULL);
130 if(credential.unLen)
132 tempVar = dmalloc (credential.unLen + 1, MDL);
133 if (!tempVar)
134 log_fatal ("no memory for ldap_username");
135 memcpy(tempVar , credential.username, credential.unLen);
136 *ldap_username = tempVar;
138 tempVar = dmalloc (credential.pwordLen + 1, MDL);
139 if (!tempVar)
140 log_fatal ("no memory for ldap_password");
141 memcpy(tempVar, credential.password, credential.pwordLen);
142 *ldap_password = tempVar;
144 #if defined (DEBUG_LDAP)
145 log_info ("Authentication credential taken from CASA");
146 #endif
148 release_casa();
149 return 1;
152 else
154 release_casa();
155 return 0;
158 else
159 return 0; //casa libraries not loaded
162 #endif /* LDAP_CASA_AUTH */