]> git.sur5r.net Git - openldap/blob - libraries/libldap/sbind.c
Update dn2domain to use str2dn() not explode_dn()
[openldap] / libraries / libldap / sbind.c
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6 /*  Portions
7  *  Copyright (c) 1993 Regents of the University of Michigan.
8  *  All rights reserved.
9  *
10  *  sbind.c
11  */
12
13 /*
14  *      BindRequest ::= SEQUENCE {
15  *              version         INTEGER,
16  *              name            DistinguishedName,       -- who
17  *              authentication  CHOICE {
18  *                      simple          [0] OCTET STRING -- passwd
19 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
20  *                      krbv42ldap      [1] OCTET STRING
21  *                      krbv42dsa       [2] OCTET STRING
22 #endif
23  *                      sasl            [3] SaslCredentials     -- LDAPv3
24  *              }
25  *      }
26  *
27  *      BindResponse ::= SEQUENCE {
28  *              COMPONENTS OF LDAPResult,
29  *              serverSaslCreds         OCTET STRING OPTIONAL -- LDAPv3
30  *      }
31  *
32  */
33
34 #include "portable.h"
35
36 #include <stdio.h>
37
38 #include <ac/socket.h>
39 #include <ac/string.h>
40 #include <ac/time.h>
41
42 #include "ldap-int.h"
43
44 /*
45  * ldap_simple_bind - bind to the ldap server (and X.500).  The dn and
46  * password of the entry to which to bind are supplied.  The message id
47  * of the request initiated is returned.
48  *
49  * Example:
50  *      ldap_simple_bind( ld, "cn=manager, o=university of michigan, c=us",
51  *          "secret" )
52  */
53
54 int
55 ldap_simple_bind(
56         LDAP *ld,
57         LDAP_CONST char *dn,
58         LDAP_CONST char *passwd )
59 {
60         int rc;
61         int msgid;
62         struct berval cred;
63
64 #ifdef NEW_LOGGING
65         LDAP_LOG ( OPERATION, ENTRY, "ldap_simple_bind\n", 0, 0, 0 );
66 #else
67         Debug( LDAP_DEBUG_TRACE, "ldap_simple_bind\n", 0, 0, 0 );
68 #endif
69
70         assert( ld != NULL );
71         assert( LDAP_VALID( ld ) );
72
73         if ( passwd != NULL ) {
74                 cred.bv_val = (char *) passwd;
75                 cred.bv_len = strlen( passwd );
76         } else {
77                 cred.bv_val = "";
78                 cred.bv_len = 0;
79         }
80
81         rc = ldap_sasl_bind( ld, dn, LDAP_SASL_SIMPLE, &cred,
82                 NULL, NULL, &msgid );
83
84         return rc == LDAP_SUCCESS ? msgid : -1;
85 }
86
87 /*
88  * ldap_simple_bind - bind to the ldap server (and X.500) using simple
89  * authentication.  The dn and password of the entry to which to bind are
90  * supplied.  LDAP_SUCCESS is returned upon success, the ldap error code
91  * otherwise.
92  *
93  * Example:
94  *      ldap_simple_bind_s( ld, "cn=manager, o=university of michigan, c=us",
95  *          "secret" )
96  */
97
98 int
99 ldap_simple_bind_s( LDAP *ld, LDAP_CONST char *dn, LDAP_CONST char *passwd )
100 {
101         struct berval cred;
102
103 #ifdef NEW_LOGGING
104         LDAP_LOG ( OPERATION, ENTRY, "ldap_simple_bind_s\n", 0, 0, 0 );
105 #else
106         Debug( LDAP_DEBUG_TRACE, "ldap_simple_bind_s\n", 0, 0, 0 );
107 #endif
108
109         if ( passwd != NULL ) {
110                 cred.bv_val = (char *) passwd;
111                 cred.bv_len = strlen( passwd );
112         } else {
113                 cred.bv_val = "";
114                 cred.bv_len = 0;
115         }
116
117         return ldap_sasl_bind_s( ld, dn, LDAP_SASL_SIMPLE, &cred,
118                 NULL, NULL, NULL );
119 }