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