3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2007 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
16 /* Portions Copyright (c) 1990 Regents of the University of Michigan.
17 * All rights reserved.
24 #include <ac/stdlib.h>
26 #include <ac/socket.h>
27 #include <ac/string.h>
34 * BindRequest ::= SEQUENCE {
36 * name DistinguishedName, -- who
37 * authentication CHOICE {
38 * simple [0] OCTET STRING -- passwd
39 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
40 * krbv42ldap [1] OCTET STRING
41 * krbv42dsa [2] OCTET STRING
43 * sasl [3] SaslCredentials -- LDAPv3
47 * BindResponse ::= SEQUENCE {
48 * COMPONENTS OF LDAPResult,
49 * serverSaslCreds OCTET STRING OPTIONAL -- LDAPv3
56 * ldap_bind - bind to the ldap server (and X.500). The dn and password
57 * of the entry to which to bind are supplied, along with the authentication
58 * method to use. The msgid of the bind request is returned on success,
59 * -1 if there's trouble. ldap_result() should be called to find out the
60 * outcome of the bind request.
63 * ldap_bind( ld, "cn=manager, o=university of michigan, c=us", "secret",
68 ldap_bind( LDAP *ld, LDAP_CONST char *dn, LDAP_CONST char *passwd, int authmethod )
70 Debug( LDAP_DEBUG_TRACE, "ldap_bind\n", 0, 0, 0 );
72 switch ( authmethod ) {
73 case LDAP_AUTH_SIMPLE:
74 return( ldap_simple_bind( ld, dn, passwd ) );
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).
94 * ldap_bind_s( ld, "cn=manager, o=university of michigan, c=us",
95 * "secret", LDAP_AUTH_SIMPLE )
96 * ldap_bind_s( ld, "cn=manager, o=university of michigan, c=us",
97 * NULL, LDAP_AUTH_KRBV4 )
103 LDAP_CONST char *passwd,
106 Debug( LDAP_DEBUG_TRACE, "ldap_bind_s\n", 0, 0, 0 );
108 switch ( authmethod ) {
109 case LDAP_AUTH_SIMPLE:
110 return( ldap_simple_bind_s( ld, dn, passwd ) );
113 /* user must use ldap_sasl_bind */
117 return( ld->ld_errno = LDAP_AUTH_UNKNOWN );