2 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6 * Copyright (c) 1993 Regents of the University of Michigan.
13 * BindRequest ::= SEQUENCE {
15 * name DistinguishedName, -- who
16 * authentication CHOICE {
17 * simple [0] OCTET STRING -- passwd
19 * krbv42ldap [1] OCTET STRING
20 * krbv42dsa [2] OCTET STRING
22 * sasl [3] SaslCredentials -- LDAPv3
26 * BindResponse ::= SEQUENCE {
27 * COMPONENTS OF LDAPResult,
28 * serverSaslCreds OCTET STRING OPTIONAL -- LDAPv3
37 #include <ac/socket.h>
38 #include <ac/string.h>
45 * ldap_simple_bind - bind to the ldap server (and X.500). The dn and
46 * password of the entry to which to bind are supplied. The message id
47 * of the request initiated is returned.
50 * ldap_simple_bind( ld, "cn=manager, o=university of michigan, c=us",
55 ldap_simple_bind( LDAP *ld, LDAP_CONST char *dn, LDAP_CONST char *passwd )
59 Debug( LDAP_DEBUG_TRACE, "ldap_simple_bind\n", 0, 0, 0 );
62 assert( LDAP_VALID( ld ) );
69 /* create a message to send */
70 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
74 assert( BER_VALID( ber ) );
77 if ( ber_printf( ber, "{it{ists}}", ++ld->ld_msgid, LDAP_REQ_BIND,
78 ld->ld_version, dn, LDAP_AUTH_SIMPLE, passwd ) == -1 ) {
79 ld->ld_errno = LDAP_ENCODING_ERROR;
85 if ( ld->ld_cache != NULL ) {
86 ldap_flush_cache( ld );
88 #endif /* !LDAP_NOCACHE */
90 /* send the message */
91 return( ldap_send_initial_request( ld, LDAP_REQ_BIND, dn, ber ));
95 * ldap_simple_bind - bind to the ldap server (and X.500) using simple
96 * authentication. The dn and password of the entry to which to bind are
97 * supplied. LDAP_SUCCESS is returned upon success, the ldap error code
101 * ldap_simple_bind_s( ld, "cn=manager, o=university of michigan, c=us",
106 ldap_simple_bind_s( LDAP *ld, LDAP_CONST char *dn, LDAP_CONST char *passwd )
111 Debug( LDAP_DEBUG_TRACE, "ldap_simple_bind_s\n", 0, 0, 0 );
113 if ( (msgid = ldap_simple_bind( ld, dn, passwd )) == -1 )
114 return( ld->ld_errno );
116 if ( ldap_result( ld, msgid, 1, NULL, &result ) == -1 )
117 return( ld->ld_errno ); /* ldap_result sets ld_errno */
119 return( ldap_result2error( ld, result, 1 ) );