/* bind.c */1/* $OpenLDAP$ */2/* This work is part of OpenLDAP Software <http://www.openldap.org/>.3*4* Copyright 1998-2024 The OpenLDAP Foundation.5* All rights reserved.6*7* Redistribution and use in source and binary forms, with or without8* modification, are permitted only as authorized by the OpenLDAP9* Public License.10*11* A copy of this license is available in the file LICENSE in the12* top-level directory of the distribution or, alternatively, at13* <http://www.OpenLDAP.org/license.html>.14*/15/* Portions Copyright (c) 1990 Regents of the University of Michigan.16* All rights reserved.17*/1819#include "portable.h"2021#include <stdio.h>2223#include <ac/stdlib.h>2425#include <ac/socket.h>26#include <ac/string.h>27#include <ac/time.h>2829#include "ldap-int.h"30#include "ldap_log.h"3132/*33* BindRequest ::= SEQUENCE {34* version INTEGER,35* name DistinguishedName, -- who36* authentication CHOICE {37* simple [0] OCTET STRING -- passwd38* krbv42ldap [1] OCTET STRING -- OBSOLETE39* krbv42dsa [2] OCTET STRING -- OBSOLETE40* sasl [3] SaslCredentials -- LDAPv341* }42* }43*44* BindResponse ::= SEQUENCE {45* COMPONENTS OF LDAPResult,46* serverSaslCreds OCTET STRING OPTIONAL -- LDAPv347* }48*49* (Source: RFC 2251)50*/5152/*53* ldap_bind - bind to the ldap server (and X.500). The dn and password54* of the entry to which to bind are supplied, along with the authentication55* method to use. The msgid of the bind request is returned on success,56* -1 if there's trouble. ldap_result() should be called to find out the57* outcome of the bind request.58*59* Example:60* ldap_bind( ld, "cn=manager, o=university of michigan, c=us", "secret",61* LDAP_AUTH_SIMPLE )62*/6364int65ldap_bind( LDAP *ld, LDAP_CONST char *dn, LDAP_CONST char *passwd, int authmethod )66{67Debug0( LDAP_DEBUG_TRACE, "ldap_bind\n" );6869switch ( authmethod ) {70case LDAP_AUTH_SIMPLE:71return( ldap_simple_bind( ld, dn, passwd ) );7273case LDAP_AUTH_SASL:74/* user must use ldap_sasl_bind */75/* FALL-THRU */7677default:78ld->ld_errno = LDAP_AUTH_UNKNOWN;79return( -1 );80}81}8283/*84* ldap_bind_s - bind to the ldap server (and X.500). The dn and password85* of the entry to which to bind are supplied, along with the authentication86* method to use. This routine just calls whichever bind routine is87* appropriate and returns the result of the bind (e.g. LDAP_SUCCESS or88* some other error indication).89*90* Examples:91* ldap_bind_s( ld, "cn=manager, o=university of michigan, c=us",92* "secret", LDAP_AUTH_SIMPLE )93* ldap_bind_s( ld, "cn=manager, o=university of michigan, c=us",94* NULL, LDAP_AUTH_KRBV4 )95*/96int97ldap_bind_s(98LDAP *ld,99LDAP_CONST char *dn,100LDAP_CONST char *passwd,101int authmethod )102{103Debug0( LDAP_DEBUG_TRACE, "ldap_bind_s\n" );104105switch ( authmethod ) {106case LDAP_AUTH_SIMPLE:107return( ldap_simple_bind_s( ld, dn, passwd ) );108109case LDAP_AUTH_SASL:110/* user must use ldap_sasl_bind */111/* FALL-THRU */112113default:114return( ld->ld_errno = LDAP_AUTH_UNKNOWN );115}116}117118119