1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
1998-08-09 08:43:13 +08:00
|
|
|
/*
|
2003-01-04 04:20:47 +08:00
|
|
|
* Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
|
1998-12-29 04:53:15 +08:00
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
|
|
|
/* Portions
|
1998-08-09 08:43:13 +08:00
|
|
|
* Copyright (c) 1993 Regents of the University of Michigan.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* sbind.c
|
|
|
|
*/
|
|
|
|
|
1999-06-04 03:22:33 +08:00
|
|
|
/*
|
|
|
|
* BindRequest ::= SEQUENCE {
|
|
|
|
* version INTEGER,
|
|
|
|
* name DistinguishedName, -- who
|
|
|
|
* authentication CHOICE {
|
|
|
|
* simple [0] OCTET STRING -- passwd
|
2000-01-09 02:42:11 +08:00
|
|
|
#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
|
1999-06-04 03:22:33 +08:00
|
|
|
* krbv42ldap [1] OCTET STRING
|
|
|
|
* krbv42dsa [2] OCTET STRING
|
|
|
|
#endif
|
|
|
|
* sasl [3] SaslCredentials -- LDAPv3
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* BindResponse ::= SEQUENCE {
|
|
|
|
* COMPONENTS OF LDAPResult,
|
|
|
|
* serverSaslCreds OCTET STRING OPTIONAL -- LDAPv3
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1998-10-25 11:13:43 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
|
1998-10-25 11:13:43 +08:00
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/time.h>
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
#include "ldap-int.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ldap_simple_bind - bind to the ldap server (and X.500). The dn and
|
|
|
|
* password of the entry to which to bind are supplied. The message id
|
|
|
|
* of the request initiated is returned.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* ldap_simple_bind( ld, "cn=manager, o=university of michigan, c=us",
|
|
|
|
* "secret" )
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
1999-06-29 07:24:16 +08:00
|
|
|
ldap_simple_bind(
|
|
|
|
LDAP *ld,
|
|
|
|
LDAP_CONST char *dn,
|
|
|
|
LDAP_CONST char *passwd )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
1999-06-29 07:24:16 +08:00
|
|
|
int rc;
|
|
|
|
int msgid;
|
|
|
|
struct berval cred;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
2002-04-02 06:31:44 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG ( OPERATION, ENTRY, "ldap_simple_bind\n", 0, 0, 0 );
|
2002-04-02 06:31:44 +08:00
|
|
|
#else
|
1998-08-09 08:43:13 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "ldap_simple_bind\n", 0, 0, 0 );
|
2002-04-02 06:31:44 +08:00
|
|
|
#endif
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-06-06 04:18:32 +08:00
|
|
|
assert( ld != NULL );
|
|
|
|
assert( LDAP_VALID( ld ) );
|
|
|
|
|
1999-06-29 07:24:16 +08:00
|
|
|
if ( passwd != NULL ) {
|
|
|
|
cred.bv_val = (char *) passwd;
|
|
|
|
cred.bv_len = strlen( passwd );
|
|
|
|
} else {
|
|
|
|
cred.bv_val = "";
|
|
|
|
cred.bv_len = 0;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
1999-06-29 07:24:16 +08:00
|
|
|
rc = ldap_sasl_bind( ld, dn, LDAP_SASL_SIMPLE, &cred,
|
|
|
|
NULL, NULL, &msgid );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-06-29 07:24:16 +08:00
|
|
|
return rc == LDAP_SUCCESS ? msgid : -1;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ldap_simple_bind - bind to the ldap server (and X.500) using simple
|
|
|
|
* authentication. The dn and password of the entry to which to bind are
|
|
|
|
* supplied. LDAP_SUCCESS is returned upon success, the ldap error code
|
|
|
|
* otherwise.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* ldap_simple_bind_s( ld, "cn=manager, o=university of michigan, c=us",
|
|
|
|
* "secret" )
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
1999-05-19 09:12:33 +08:00
|
|
|
ldap_simple_bind_s( LDAP *ld, LDAP_CONST char *dn, LDAP_CONST char *passwd )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
1999-06-29 07:24:16 +08:00
|
|
|
struct berval cred;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
2002-04-02 06:31:44 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG ( OPERATION, ENTRY, "ldap_simple_bind_s\n", 0, 0, 0 );
|
2002-04-02 06:31:44 +08:00
|
|
|
#else
|
1998-08-09 08:43:13 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "ldap_simple_bind_s\n", 0, 0, 0 );
|
2002-04-02 06:31:44 +08:00
|
|
|
#endif
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-06-29 07:24:16 +08:00
|
|
|
if ( passwd != NULL ) {
|
|
|
|
cred.bv_val = (char *) passwd;
|
|
|
|
cred.bv_len = strlen( passwd );
|
|
|
|
} else {
|
|
|
|
cred.bv_val = "";
|
|
|
|
cred.bv_len = 0;
|
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-06-29 07:24:16 +08:00
|
|
|
return ldap_sasl_bind_s( ld, dn, LDAP_SASL_SIMPLE, &cred,
|
|
|
|
NULL, NULL, NULL );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|