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