]> git.sur5r.net Git - openldap/blob - libraries/libldap/bind.c
create SASL_LIBS to hold -lsasl
[openldap] / libraries / libldap / bind.c
1 /*
2  * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
3  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
4  */
5 /*  Portions
6  *  Copyright (c) 1990 Regents of the University of Michigan.
7  *  All rights reserved.
8  *
9  *  bind.c
10  */
11
12 /*
13  *      BindRequest ::= SEQUENCE {
14  *              version         INTEGER,
15  *              name            DistinguishedName,       -- who
16  *              authentication  CHOICE {
17  *                      simple          [0] OCTET STRING -- passwd
18 #ifdef HAVE_KERBEROS
19  *                      krbv42ldap      [1] OCTET STRING
20  *                      krbv42dsa       [2] OCTET STRING
21 #endif
22  *                      sasl            [3] SaslCredentials     -- LDAPv3
23  *              }
24  *      }
25  *
26  *      BindResponse ::= SEQUENCE {
27  *              COMPONENTS OF LDAPResult,
28  *              serverSaslCreds         OCTET STRING OPTIONAL -- LDAPv3
29  *      }
30  *
31  */
32
33 #include "portable.h"
34
35 #include <stdio.h>
36
37 #include <ac/stdlib.h>
38
39 #include <ac/socket.h>
40 #include <ac/string.h>
41 #include <ac/time.h>
42
43 #include "ldap-int.h"
44
45
46 /*
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.
53  *
54  * Example:
55  *      ldap_bind( ld, "cn=manager, o=university of michigan, c=us", "secret",
56  *          LDAP_AUTH_SIMPLE )
57  */
58
59 int
60 ldap_bind( LDAP *ld, LDAP_CONST char *dn, LDAP_CONST char *passwd, int authmethod )
61 {
62         Debug( LDAP_DEBUG_TRACE, "ldap_bind\n", 0, 0, 0 );
63
64         switch ( authmethod ) {
65         case LDAP_AUTH_SIMPLE:
66                 return( ldap_simple_bind( ld, dn, passwd ) );
67
68 #ifdef HAVE_KERBEROS
69         case LDAP_AUTH_KRBV41:
70                 return( ldap_kerberos_bind1( ld, dn ) );
71
72         case LDAP_AUTH_KRBV42:
73                 return( ldap_kerberos_bind2( ld, dn ) );
74 #endif
75
76         case LDAP_AUTH_SASL:
77                 /* user must use ldap_sasl_bind */
78                 /* FALL-THRU */
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(
102         LDAP *ld,
103         LDAP_CONST char *dn,
104         LDAP_CONST char *passwd,
105         int authmethod )
106 {
107         Debug( LDAP_DEBUG_TRACE, "ldap_bind_s\n", 0, 0, 0 );
108
109         switch ( authmethod ) {
110         case LDAP_AUTH_SIMPLE:
111                 return( ldap_simple_bind_s( ld, dn, passwd ) );
112
113 #ifdef HAVE_KERBEROS
114         case LDAP_AUTH_KRBV4:
115                 return( ldap_kerberos_bind_s( ld, dn ) );
116
117         case LDAP_AUTH_KRBV41:
118                 return( ldap_kerberos_bind1_s( ld, dn ) );
119
120         case LDAP_AUTH_KRBV42:
121                 return( ldap_kerberos_bind2_s( ld, dn ) );
122 #endif
123
124         case LDAP_AUTH_SASL:
125                 /* user must use ldap_sasl_bind */
126                 /* FALL-THRU */
127
128         default:
129                 return( ld->ld_errno = LDAP_AUTH_UNKNOWN );
130         }
131 }
132
133
134 void
135 ldap_set_rebind_proc( LDAP *ld, int (*rebindproc)( LDAP *ld, char **dnp,
136         char **passwdp, int *authmethodp, int freeit ))
137 {
138         assert( ld != NULL );
139         assert( LDAP_VALID( ld ) );
140
141         ld->ld_rebindproc = rebindproc;
142 }