ISC DHCP  4.3.1
A reference DHCPv4 and DHCPv6 implementation
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ldap_casa.c
Go to the documentation of this file.
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)
58 #include "ldap_casa.h"
59 #include "dhcpd.h"
60 
61 int
62 load_casa (void)
63 {
64  if( !(casaIDK = dlopen(MICASA_LIB,RTLD_LAZY)))
65  return 0;
66  p_miCASAGetCredential = (CASA_GetCredential_T) dlsym(casaIDK, "miCASAGetCredential");
67  p_miCASASetCredential = (CASA_SetCredential_T) dlsym(casaIDK, "miCASASetCredential");
68  p_miCASARemoveCredential = (CASA_RemoveCredential_T) dlsym(casaIDK, "miCASARemoveCredential");
69 
70  if((p_miCASAGetCredential == NULL) ||
71  (p_miCASASetCredential == NULL) ||
72  (p_miCASARemoveCredential == NULL))
73  {
74  if(casaIDK)
75  dlclose(casaIDK);
76  casaIDK = NULL;
77  p_miCASAGetCredential = NULL;
78  p_miCASASetCredential = NULL;
79  p_miCASARemoveCredential = NULL;
80  return 0;
81  }
82  else
83  return 1;
84 }
85 
86 static void
87 release_casa(void)
88 {
89  if(casaIDK)
90  {
91  dlclose(casaIDK);
92  casaIDK = NULL;
93  }
94 
95  p_miCASAGetCredential = NULL;
96  p_miCASASetCredential = NULL;
97  p_miCASARemoveCredential = NULL;
98 
99 }
100 
101 int
102 load_uname_pwd_from_miCASA (char **ldap_username, char **ldap_password)
103  {
104  int result = 0;
105  uint32_t credentialtype = SSCS_CRED_TYPE_SERVER_F;
106  SSCS_BASIC_CREDENTIAL credential;
107  SSCS_SECRET_ID_T applicationSecretId;
108  char *tempVar = NULL;
109 
110  const char applicationName[10] = "dhcp-ldap";
111 
112  if ( load_casa() )
113  {
114  memset(&credential, 0, sizeof(SSCS_BASIC_CREDENTIAL));
115  memset(&applicationSecretId, 0, sizeof(SSCS_SECRET_ID_T));
116 
117  applicationSecretId.len = strlen(applicationName) + 1;
118  memcpy (applicationSecretId.id, applicationName, applicationSecretId.len);
119 
120  credential.unFlags = USERNAME_TYPE_CN_F;
121 
122  result = p_miCASAGetCredential (0,
123  &applicationSecretId,NULL,&credentialtype,
124  &credential,NULL);
125 
126  if(credential.unLen)
127  {
128  tempVar = dmalloc (credential.unLen + 1, MDL);
129  if (!tempVar)
130  log_fatal ("no memory for ldap_username");
131  memcpy(tempVar , credential.username, credential.unLen);
132  *ldap_username = tempVar;
133 
134  tempVar = dmalloc (credential.pwordLen + 1, MDL);
135  if (!tempVar)
136  log_fatal ("no memory for ldap_password");
137  memcpy(tempVar, credential.password, credential.pwordLen);
138  *ldap_password = tempVar;
139 
140 #if defined (DEBUG_LDAP)
141  log_info ("Authentication credential taken from CASA");
142 #endif
143 
144  release_casa();
145  return 1;
146 
147  }
148  else
149  {
150  release_casa();
151  return 0;
152  }
153  }
154  else
155  return 0; //casa libraries not loaded
156  }
157 
158 #endif /* LDAP_CASA_AUTH */
159 
void * dmalloc(unsigned, const char *, int)
Definition: alloc.c:56
#define MDL
Definition: omapip.h:568
void log_fatal(const char *,...) __attribute__((__format__(__printf__
int int log_info(const char *,...) __attribute__((__format__(__printf__