]> git.sur5r.net Git - openldap/blob - libraries/libldap/bind.c
More files that didn't get merged properly.
[openldap] / libraries / libldap / bind.c
1 /*
2  *  Copyright (c) 1990 Regents of the University of Michigan.
3  *  All rights reserved.
4  *
5  *  bind.c
6  */
7
8 #include "portable.h"
9
10 #ifndef lint 
11 static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
12 #endif
13
14 #include <stdio.h>
15 #include <stdlib.h>
16
17 #include <ac/socket.h>
18 #include <ac/string.h>
19 #include <ac/time.h>
20
21 #include "lber.h"
22 #include "ldap.h"
23
24
25 /*
26  * ldap_bind - bind to the ldap server (and X.500).  The dn and password
27  * of the entry to which to bind are supplied, along with the authentication
28  * method to use.  The msgid of the bind request is returned on success,
29  * -1 if there's trouble.  Note, the kerberos support assumes the user already
30  * has a valid tgt for now.  ldap_result() should be called to find out the
31  * outcome of the bind request.
32  *
33  * Example:
34  *      ldap_bind( ld, "cn=manager, o=university of michigan, c=us", "secret",
35  *          LDAP_AUTH_SIMPLE )
36  */
37
38 int
39 ldap_bind( LDAP *ld, char *dn, char *passwd, int authmethod )
40 {
41         /*
42          * The bind request looks like this:
43          *      BindRequest ::= SEQUENCE {
44          *              version         INTEGER,
45          *              name            DistinguishedName,       -- who
46          *              authentication  CHOICE {
47          *                      simple          [0] OCTET STRING -- passwd
48 #ifdef HAVE_KERBEROS
49          *                      krbv42ldap      [1] OCTET STRING
50          *                      krbv42dsa       [2] OCTET STRING
51 #endif
52          *              }
53          *      }
54          * all wrapped up in an LDAPMessage sequence.
55          */
56
57         Debug( LDAP_DEBUG_TRACE, "ldap_bind\n", 0, 0, 0 );
58
59         switch ( authmethod ) {
60         case LDAP_AUTH_SIMPLE:
61                 return( ldap_simple_bind( ld, dn, passwd ) );
62
63 #ifdef HAVE_KERBEROS
64         case LDAP_AUTH_KRBV41:
65                 return( ldap_kerberos_bind1( ld, dn ) );
66
67         case LDAP_AUTH_KRBV42:
68                 return( ldap_kerberos_bind2( ld, dn ) );
69 #endif
70
71         default:
72                 ld->ld_errno = LDAP_AUTH_UNKNOWN;
73                 return( -1 );
74         }
75 }
76
77 /*
78  * ldap_bind_s - bind to the ldap server (and X.500).  The dn and password
79  * of the entry to which to bind are supplied, along with the authentication
80  * method to use.  This routine just calls whichever bind routine is
81  * appropriate and returns the result of the bind (e.g. LDAP_SUCCESS or
82  * some other error indication).  Note, the kerberos support assumes the
83  * user already has a valid tgt for now.
84  *
85  * Examples:
86  *      ldap_bind_s( ld, "cn=manager, o=university of michigan, c=us",
87  *          "secret", LDAP_AUTH_SIMPLE )
88  *      ldap_bind_s( ld, "cn=manager, o=university of michigan, c=us",
89  *          NULL, LDAP_AUTH_KRBV4 )
90  */
91 int
92 ldap_bind_s( LDAP *ld, char *dn, char *passwd, int authmethod )
93 {
94         Debug( LDAP_DEBUG_TRACE, "ldap_bind_s\n", 0, 0, 0 );
95
96         switch ( authmethod ) {
97         case LDAP_AUTH_SIMPLE:
98                 return( ldap_simple_bind_s( ld, dn, passwd ) );
99
100 #ifdef HAVE_KERBEROS
101         case LDAP_AUTH_KRBV4:
102                 return( ldap_kerberos_bind_s( ld, dn ) );
103
104         case LDAP_AUTH_KRBV41:
105                 return( ldap_kerberos_bind1_s( ld, dn ) );
106
107         case LDAP_AUTH_KRBV42:
108                 return( ldap_kerberos_bind2_s( ld, dn ) );
109 #endif
110
111         default:
112                 return( ld->ld_errno = LDAP_AUTH_UNKNOWN );
113         }
114 }
115
116
117 #ifdef LDAP_REFERRALS
118 void
119 ldap_set_rebind_proc( LDAP *ld, int (*rebindproc)( LDAP *ld, char **dnp,
120         char **passwdp, int *authmethodp, int freeit ))
121 {
122         ld->ld_rebindproc = rebindproc;
123 }
124 #endif /* LDAP_REFERRALS */