2 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6 * Copyright (c) 1990 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/stdlib.h>
39 #include <ac/socket.h>
40 #include <ac/string.h>
47 * ldap_bind - bind to the ldap server (and X.500). The dn and password
48 * of the entry to which to bind are supplied, along with the authentication
49 * method to use. The msgid of the bind request is returned on success,
50 * -1 if there's trouble. Note, the kerberos support assumes the user already
51 * has a valid tgt for now. ldap_result() should be called to find out the
52 * outcome of the bind request.
55 * ldap_bind( ld, "cn=manager, o=university of michigan, c=us", "secret",
60 ldap_bind( LDAP *ld, LDAP_CONST char *dn, LDAP_CONST char *passwd, int authmethod )
62 Debug( LDAP_DEBUG_TRACE, "ldap_bind\n", 0, 0, 0 );
64 switch ( authmethod ) {
65 case LDAP_AUTH_SIMPLE:
66 return( ldap_simple_bind( ld, dn, passwd ) );
69 case LDAP_AUTH_KRBV41:
70 return( ldap_kerberos_bind1( ld, dn ) );
72 case LDAP_AUTH_KRBV42:
73 return( ldap_kerberos_bind2( ld, dn ) );
77 /* user must use ldap_sasl_bind */
81 ld->ld_errno = LDAP_AUTH_UNKNOWN;
87 * ldap_bind_s - bind to the ldap server (and X.500). The dn and password
88 * of the entry to which to bind are supplied, along with the authentication
89 * method to use. This routine just calls whichever bind routine is
90 * appropriate and returns the result of the bind (e.g. LDAP_SUCCESS or
91 * some other error indication). Note, the kerberos support assumes the
92 * user already has a valid tgt for now.
95 * ldap_bind_s( ld, "cn=manager, o=university of michigan, c=us",
96 * "secret", LDAP_AUTH_SIMPLE )
97 * ldap_bind_s( ld, "cn=manager, o=university of michigan, c=us",
98 * NULL, LDAP_AUTH_KRBV4 )
104 LDAP_CONST char *passwd,
107 Debug( LDAP_DEBUG_TRACE, "ldap_bind_s\n", 0, 0, 0 );
109 switch ( authmethod ) {
110 case LDAP_AUTH_SIMPLE:
111 return( ldap_simple_bind_s( ld, dn, passwd ) );
114 case LDAP_AUTH_KRBV4:
115 return( ldap_kerberos_bind_s( ld, dn ) );
117 case LDAP_AUTH_KRBV41:
118 return( ldap_kerberos_bind1_s( ld, dn ) );
120 case LDAP_AUTH_KRBV42:
121 return( ldap_kerberos_bind2_s( ld, dn ) );
125 /* user must use ldap_sasl_bind */
129 return( ld->ld_errno = LDAP_AUTH_UNKNOWN );
135 ldap_set_rebind_proc( LDAP *ld, int (*rebindproc)( LDAP *ld, char **dnp,
136 char **passwdp, int *authmethodp, int freeit ))
138 assert( ld != NULL );
139 assert( LDAP_VALID( ld ) );
141 ld->ld_rebindproc = rebindproc;