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

  1. /* $OpenLDAP: pkg/ldap/libraries/libldap/sbind.c,v 1.12.4.2 2000/06/13 17:57:20 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) 1993 Regents of the University of Michigan.
  8.  *  All rights reserved.
  9.  *
  10.  *  sbind.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/socket.h>
  39. #include <ac/string.h>
  40. #include <ac/time.h>
  41.  
  42. #include "ldap-int.h"
  43.  
  44.  
  45. /*
  46.  * ldap_simple_bind - bind to the ldap server (and X.500).  The dn and
  47.  * password of the entry to which to bind are supplied.  The message id
  48.  * of the request initiated is returned.
  49.  *
  50.  * Example:
  51.  *    ldap_simple_bind( ld, "cn=manager, o=university of michigan, c=us",
  52.  *        "secret" )
  53.  */
  54.  
  55. int
  56. ldap_simple_bind(
  57.     LDAP *ld,
  58.     LDAP_CONST char *dn,
  59.     LDAP_CONST char *passwd )
  60. {
  61.     int rc;
  62.     int msgid;
  63.     struct berval cred;
  64.  
  65.     Debug( LDAP_DEBUG_TRACE, "ldap_simple_bind\n", 0, 0, 0 );
  66.  
  67.     assert( ld != NULL );
  68.     assert( LDAP_VALID( ld ) );
  69.  
  70.     if ( passwd != NULL ) {
  71.         cred.bv_val = (char *) passwd;
  72.         cred.bv_len = strlen( passwd );
  73.     } else {
  74.         cred.bv_val = "";
  75.         cred.bv_len = 0;
  76.     }
  77.  
  78.     rc = ldap_sasl_bind( ld, dn, LDAP_SASL_SIMPLE, &cred,
  79.         NULL, NULL, &msgid );
  80.  
  81.     return rc == LDAP_SUCCESS ? msgid : -1;
  82. }
  83.  
  84. /*
  85.  * ldap_simple_bind - bind to the ldap server (and X.500) using simple
  86.  * authentication.  The dn and password of the entry to which to bind are
  87.  * supplied.  LDAP_SUCCESS is returned upon success, the ldap error code
  88.  * otherwise.
  89.  *
  90.  * Example:
  91.  *    ldap_simple_bind_s( ld, "cn=manager, o=university of michigan, c=us",
  92.  *        "secret" )
  93.  */
  94.  
  95. int
  96. ldap_simple_bind_s( LDAP *ld, LDAP_CONST char *dn, LDAP_CONST char *passwd )
  97. {
  98.     struct berval cred;
  99.  
  100.     Debug( LDAP_DEBUG_TRACE, "ldap_simple_bind_s\n", 0, 0, 0 );
  101.  
  102.     if ( passwd != NULL ) {
  103.         cred.bv_val = (char *) passwd;
  104.         cred.bv_len = strlen( passwd );
  105.     } else {
  106.         cred.bv_val = "";
  107.         cred.bv_len = 0;
  108.     }
  109.  
  110.     return ldap_sasl_bind_s( ld, dn, LDAP_SASL_SIMPLE, &cred,
  111.         NULL, NULL, NULL );
  112. }
  113.