No empty .Rs/.Re
[netbsd-mini2440.git] / external / bsd / openldap / dist / libraries / libldap / sbind.c
blob669a995bc481ae48b480ce4bf5aa3a526dba7b53
1 /* $OpenLDAP: pkg/ldap/libraries/libldap/sbind.c,v 1.25.2.3 2008/02/11 23:26:41 kurt Exp $ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2008 The OpenLDAP Foundation.
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
9 * Public License.
11 * A copy of this license is available in the file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
15 /* Portions Copyright (c) 1993 Regents of the University of Michigan.
16 * All rights reserved.
20 * BindRequest ::= SEQUENCE {
21 * version INTEGER,
22 * name DistinguishedName, -- who
23 * authentication CHOICE {
24 * simple [0] OCTET STRING -- passwd
25 * krbv42ldap [1] OCTET STRING -- OBSOLETE
26 * krbv42dsa [2] OCTET STRING -- OBSOLETE
27 * sasl [3] SaslCredentials -- LDAPv3
28 * }
29 * }
31 * BindResponse ::= SEQUENCE {
32 * COMPONENTS OF LDAPResult,
33 * serverSaslCreds OCTET STRING OPTIONAL -- LDAPv3
34 * }
38 #include "portable.h"
40 #include <stdio.h>
42 #include <ac/socket.h>
43 #include <ac/string.h>
44 #include <ac/time.h>
46 #include "ldap-int.h"
49 * ldap_simple_bind - bind to the ldap server (and X.500). The dn and
50 * password of the entry to which to bind are supplied. The message id
51 * of the request initiated is returned.
53 * Example:
54 * ldap_simple_bind( ld, "cn=manager, o=university of michigan, c=us",
55 * "secret" )
58 int
59 ldap_simple_bind(
60 LDAP *ld,
61 LDAP_CONST char *dn,
62 LDAP_CONST char *passwd )
64 int rc;
65 int msgid;
66 struct berval cred;
68 Debug( LDAP_DEBUG_TRACE, "ldap_simple_bind\n", 0, 0, 0 );
70 assert( ld != NULL );
71 assert( LDAP_VALID( ld ) );
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;
81 rc = ldap_sasl_bind( ld, dn, LDAP_SASL_SIMPLE, &cred,
82 NULL, NULL, &msgid );
84 return rc == LDAP_SUCCESS ? msgid : -1;
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.
93 * Example:
94 * ldap_simple_bind_s( ld, "cn=manager, o=university of michigan, c=us",
95 * "secret" )
98 int
99 ldap_simple_bind_s( LDAP *ld, LDAP_CONST char *dn, LDAP_CONST char *passwd )
101 struct berval cred;
103 Debug( LDAP_DEBUG_TRACE, "ldap_simple_bind_s\n", 0, 0, 0 );
105 if ( passwd != NULL ) {
106 cred.bv_val = (char *) passwd;
107 cred.bv_len = strlen( passwd );
108 } else {
109 cred.bv_val = "";
110 cred.bv_len = 0;
113 return ldap_sasl_bind_s( ld, dn, LDAP_SASL_SIMPLE, &cred,
114 NULL, NULL, NULL );