server/ldap_casa.c

Go to the documentation of this file.
00001 /* ldap_casa.c
00002    
00003    CASA routines for DHCPD... */
00004 
00005 /* Copyright (c) 2006 Novell, Inc.
00006 
00007  * All rights reserved.
00008  * Redistribution and use in source and binary forms, with or without 
00009  * modification, are permitted provided that the following conditions are met: 
00010  * 1.Redistributions of source code must retain the above copyright notice, 
00011  *   this list of conditions and the following disclaimer. 
00012  * 2.Redistributions in binary form must reproduce the above copyright notice, 
00013  *   this list of conditions and the following disclaimer in the documentation 
00014  *   and/or other materials provided with the distribution. 
00015  * 3.Neither the name of ISC, ISC DHCP, nor the names of its contributors 
00016  *   may be used to endorse or promote products derived from this software 
00017  *   without specific prior written permission. 
00018 
00019  * THIS SOFTWARE IS PROVIDED BY INTERNET SYSTEMS CONSORTIUM AND CONTRIBUTORS 
00020  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
00021  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
00022  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ISC OR CONTRIBUTORS BE LIABLE 
00023  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
00024  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
00025  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
00026  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
00027  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
00028  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
00029  * POSSIBILITY OF SUCH DAMAGE.
00030 
00031  * This file was written by S Kalyanasundaram <skalyanasundaram@novell.com>
00032  */
00033 
00034 /*
00035  * Copyright (c) 2004-2010 by Internet Systems Consortium, Inc. ("ISC")
00036  * Copyright (c) 1995-2003 by Internet Software Consortium
00037  *
00038  * Permission to use, copy, modify, and distribute this software for any
00039  * purpose with or without fee is hereby granted, provided that the above
00040  * copyright notice and this permission notice appear in all copies.
00041  *
00042  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
00043  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
00044  * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
00045  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00046  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00047  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
00048  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00049  *
00050  *   Internet Systems Consortium, Inc.
00051  *   950 Charter Street
00052  *   Redwood City, CA 94063
00053  *   <info@isc.org>
00054  *   https://www.isc.org/
00055  */
00056 
00057 #if defined(LDAP_CASA_AUTH)
00058 #include "ldap_casa.h"
00059 #include "dhcpd.h"
00060 
00061 int
00062 load_casa (void)
00063 {
00064        if( !(casaIDK = dlopen(MICASA_LIB,RTLD_LAZY)))
00065           return 0;
00066        p_miCASAGetCredential = (CASA_GetCredential_T) dlsym(casaIDK, "miCASAGetCredential");
00067        p_miCASASetCredential = (CASA_SetCredential_T) dlsym(casaIDK, "miCASASetCredential");
00068        p_miCASARemoveCredential = (CASA_RemoveCredential_T) dlsym(casaIDK, "miCASARemoveCredential");
00069 
00070        if((p_miCASAGetCredential == NULL) ||
00071          (p_miCASASetCredential == NULL) ||
00072          (p_miCASARemoveCredential == NULL))
00073        {
00074           if(casaIDK)
00075             dlclose(casaIDK);
00076           casaIDK = NULL;
00077           p_miCASAGetCredential = NULL;
00078           p_miCASASetCredential = NULL;
00079           p_miCASARemoveCredential = NULL;
00080           return 0;
00081        }
00082        else
00083           return 1;
00084 }
00085 
00086 static void
00087 release_casa(void)
00088 {
00089    if(casaIDK)
00090    {
00091       dlclose(casaIDK);
00092       casaIDK = NULL;
00093    }
00094 
00095    p_miCASAGetCredential = NULL;
00096    p_miCASASetCredential = NULL;
00097    p_miCASARemoveCredential = NULL;
00098 
00099 }
00100 
00101 int
00102 load_uname_pwd_from_miCASA (char **ldap_username, char **ldap_password)
00103  {
00104    int                     result = 0;
00105    uint32_t                credentialtype = SSCS_CRED_TYPE_SERVER_F;
00106    SSCS_BASIC_CREDENTIAL   credential;
00107    SSCS_SECRET_ID_T        applicationSecretId;
00108    char                    *tempVar = NULL;
00109 
00110    const char applicationName[10] = "dhcp-ldap";
00111 
00112    if ( load_casa() )
00113    {
00114       memset(&credential, 0, sizeof(SSCS_BASIC_CREDENTIAL));
00115       memset(&applicationSecretId, 0, sizeof(SSCS_SECRET_ID_T));
00116 
00117       applicationSecretId.len = strlen(applicationName) + 1;
00118       memcpy (applicationSecretId.id, applicationName, applicationSecretId.len);
00119 
00120       credential.unFlags = USERNAME_TYPE_CN_F;
00121 
00122       result = p_miCASAGetCredential (0,
00123                  &applicationSecretId,NULL,&credentialtype,
00124                  &credential,NULL);
00125 
00126       if(credential.unLen)
00127       {
00128          tempVar = dmalloc (credential.unLen + 1, MDL);
00129          if (!tempVar)
00130              log_fatal ("no memory for ldap_username");
00131          memcpy(tempVar , credential.username, credential.unLen);
00132          *ldap_username = tempVar;
00133 
00134          tempVar = dmalloc (credential.pwordLen + 1, MDL);
00135          if (!tempVar)
00136              log_fatal ("no memory for ldap_password");
00137          memcpy(tempVar, credential.password, credential.pwordLen);
00138          *ldap_password = tempVar;
00139 
00140 #if defined (DEBUG_LDAP)
00141          log_info ("Authentication credential taken from CASA");
00142 #endif
00143 
00144          release_casa();
00145          return 1;
00146 
00147         }
00148         else
00149         {
00150             release_casa();
00151             return 0;
00152         }
00153       }
00154       else
00155           return 0; //casa libraries not loaded
00156  }
00157 
00158 #endif /* LDAP_CASA_AUTH */
00159 

Generated on 5 Apr 2014 for ISC DHCP by  doxygen 1.6.1