home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ldapsdk.zip / libraries / libldap / bind.c < prev    next >
C/C++ Source or Header  |  2000-06-14  |  3KB  |  133 lines

  1. /* $OpenLDAP: pkg/ldap/libraries/libldap/bind.c,v 1.10.8.2 2000/06/13 17:57:18 kurt Exp $ */
  2. /*
  3.  * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
  4.  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  5.  */
  6. /*  Portions
  7.  *  Copyright (c) 1990 Regents of the University of Michigan.
  8.  *  All rights reserved.
  9.  *
  10.  *  bind.c
  11.  */
  12.  
  13. /*
  14.  *    BindRequest ::= SEQUENCE {
  15.  *        version        INTEGER,
  16.  *        name        DistinguishedName,     -- who
  17.  *        authentication    CHOICE {
  18.  *            simple        [0] OCTET STRING -- passwd
  19. #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
  20.  *            krbv42ldap    [1] OCTET STRING
  21.  *            krbv42dsa    [2] OCTET STRING
  22. #endif
  23.  *            sasl        [3] SaslCredentials    -- LDAPv3
  24.  *        }
  25.  *    }
  26.  *
  27.  *    BindResponse ::= SEQUENCE {
  28.  *        COMPONENTS OF LDAPResult,
  29.  *        serverSaslCreds        OCTET STRING OPTIONAL -- LDAPv3
  30.  *    }
  31.  *
  32.  */
  33.  
  34. #include "portable.h"
  35.  
  36. #include <stdio.h>
  37.  
  38. #include <ac/stdlib.h>
  39.  
  40. #include <ac/socket.h>
  41. #include <ac/string.h>
  42. #include <ac/time.h>
  43.  
  44. #include "ldap-int.h"
  45.  
  46.  
  47. /*
  48.  * ldap_bind - bind to the ldap server (and X.500).  The dn and password
  49.  * of the entry to which to bind are supplied, along with the authentication
  50.  * method to use.  The msgid of the bind request is returned on success,
  51.  * -1 if there's trouble.  Note, the kerberos support assumes the user already
  52.  * has a valid tgt for now.  ldap_result() should be called to find out the
  53.  * outcome of the bind request.
  54.  *
  55.  * Example:
  56.  *    ldap_bind( ld, "cn=manager, o=university of michigan, c=us", "secret",
  57.  *        LDAP_AUTH_SIMPLE )
  58.  */
  59.  
  60. int
  61. ldap_bind( LDAP *ld, LDAP_CONST char *dn, LDAP_CONST char *passwd, int authmethod )
  62. {
  63.     Debug( LDAP_DEBUG_TRACE, "ldap_bind\n", 0, 0, 0 );
  64.  
  65.     switch ( authmethod ) {
  66.     case LDAP_AUTH_SIMPLE:
  67.         return( ldap_simple_bind( ld, dn, passwd ) );
  68.  
  69. #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
  70.     case LDAP_AUTH_KRBV41:
  71.         return( ldap_kerberos_bind1( ld, dn ) );
  72.  
  73.     case LDAP_AUTH_KRBV42:
  74.         return( ldap_kerberos_bind2( ld, dn ) );
  75. #endif
  76.  
  77.     case LDAP_AUTH_SASL:
  78.         /* user must use ldap_sasl_bind */
  79.         /* FALL-THRU */
  80.  
  81.     default:
  82.         ld->ld_errno = LDAP_AUTH_UNKNOWN;
  83.         return( -1 );
  84.     }
  85. }
  86.  
  87. /*
  88.  * ldap_bind_s - bind to the ldap server (and X.500).  The dn and password
  89.  * of the entry to which to bind are supplied, along with the authentication
  90.  * method to use.  This routine just calls whichever bind routine is
  91.  * appropriate and returns the result of the bind (e.g. LDAP_SUCCESS or
  92.  * some other error indication).  Note, the kerberos support assumes the
  93.  * user already has a valid tgt for now.
  94.  *
  95.  * Examples:
  96.  *    ldap_bind_s( ld, "cn=manager, o=university of michigan, c=us",
  97.  *        "secret", LDAP_AUTH_SIMPLE )
  98.  *    ldap_bind_s( ld, "cn=manager, o=university of michigan, c=us",
  99.  *        NULL, LDAP_AUTH_KRBV4 )
  100.  */
  101. int
  102. ldap_bind_s(
  103.     LDAP *ld,
  104.     LDAP_CONST char *dn,
  105.     LDAP_CONST char *passwd,
  106.     int authmethod )
  107. {
  108.     Debug( LDAP_DEBUG_TRACE, "ldap_bind_s\n", 0, 0, 0 );
  109.  
  110.     switch ( authmethod ) {
  111.     case LDAP_AUTH_SIMPLE:
  112.         return( ldap_simple_bind_s( ld, dn, passwd ) );
  113.  
  114. #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
  115.     case LDAP_AUTH_KRBV4:
  116.         return( ldap_kerberos_bind_s( ld, dn ) );
  117.  
  118.     case LDAP_AUTH_KRBV41:
  119.         return( ldap_kerberos_bind1_s( ld, dn ) );
  120.  
  121.     case LDAP_AUTH_KRBV42:
  122.         return( ldap_kerberos_bind2_s( ld, dn ) );
  123. #endif
  124.  
  125.     case LDAP_AUTH_SASL:
  126.         /* user must use ldap_sasl_bind */
  127.         /* FALL-THRU */
  128.  
  129.     default:
  130.         return( ld->ld_errno = LDAP_AUTH_UNKNOWN );
  131.     }
  132. }
  133.