3 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
7 * Copyright (c) 1990 Regents of the University of Michigan.
14 * BindRequest ::= SEQUENCE {
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
23 * sasl [3] SaslCredentials -- LDAPv3
27 * BindResponse ::= SEQUENCE {
28 * COMPONENTS OF LDAPResult,
29 * serverSaslCreds OCTET STRING OPTIONAL -- LDAPv3
38 #include <ac/stdlib.h>
40 #include <ac/socket.h>
41 #include <ac/string.h>
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.
56 * ldap_bind( ld, "cn=manager, o=university of michigan, c=us", "secret",
61 ldap_bind( LDAP *ld, LDAP_CONST char *dn, LDAP_CONST char *passwd, int authmethod )
64 LDAP_LOG (( "bind", LDAP_LEVEL_ENTRY, "ldap_bind\n" ));
66 Debug( LDAP_DEBUG_TRACE, "ldap_bind\n", 0, 0, 0 );
69 switch ( authmethod ) {
70 case LDAP_AUTH_SIMPLE:
71 return( ldap_simple_bind( ld, dn, passwd ) );
73 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
74 case LDAP_AUTH_KRBV41:
75 return( ldap_kerberos_bind1( ld, dn ) );
77 case LDAP_AUTH_KRBV42:
78 return( ldap_kerberos_bind2( ld, dn ) );
82 /* user must use ldap_sasl_bind */
86 ld->ld_errno = LDAP_AUTH_UNKNOWN;
92 * ldap_bind_s - bind to the ldap server (and X.500). The dn and password
93 * of the entry to which to bind are supplied, along with the authentication
94 * method to use. This routine just calls whichever bind routine is
95 * appropriate and returns the result of the bind (e.g. LDAP_SUCCESS or
96 * some other error indication). Note, the kerberos support assumes the
97 * user already has a valid tgt for now.
100 * ldap_bind_s( ld, "cn=manager, o=university of michigan, c=us",
101 * "secret", LDAP_AUTH_SIMPLE )
102 * ldap_bind_s( ld, "cn=manager, o=university of michigan, c=us",
103 * NULL, LDAP_AUTH_KRBV4 )
109 LDAP_CONST char *passwd,
113 LDAP_LOG (( "bind", LDAP_LEVEL_ENTRY, "ldap_bind_s\n" ));
115 Debug( LDAP_DEBUG_TRACE, "ldap_bind_s\n", 0, 0, 0 );
118 switch ( authmethod ) {
119 case LDAP_AUTH_SIMPLE:
120 return( ldap_simple_bind_s( ld, dn, passwd ) );
122 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
123 case LDAP_AUTH_KRBV4:
124 return( ldap_kerberos_bind_s( ld, dn ) );
126 case LDAP_AUTH_KRBV41:
127 return( ldap_kerberos_bind1_s( ld, dn ) );
129 case LDAP_AUTH_KRBV42:
130 return( ldap_kerberos_bind2_s( ld, dn ) );
134 /* user must use ldap_sasl_bind */
138 return( ld->ld_errno = LDAP_AUTH_UNKNOWN );