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