openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/nss-pam-ldapd/0.9.8-r0/nss-pam-ldapd-0.9.8/nslcd/myldap.c
static int do_bind(MYLDAP_SESSION* session, LDAP* ld, const char* uri)
{
    int rc;
#ifdef HAVE_LDAP_SASL_INTERACTIVE_BIND_S
#ifndef HAVE_SASL_INTERACT_T
    struct berval cred;
#endif /* not HAVE_SASL_INTERACT_T */
#endif /* HAVE_LDAP_SASL_INTERACTIVE_BIND_S */
#ifdef LDAP_OPT_X_TLS
    /* check if StartTLS is requested */
    if (nslcd_cfg->ssl == SSL_START_TLS)
    {
        log_log(LOG_DEBUG, "ldap_start_tls_s()");
        errno = 0;
        rc = ldap_start_tls_s(ld, NULL, NULL);
        if (rc != LDAP_SUCCESS)
        {
            myldap_err(LOG_WARNING, ld, rc,
                       "ldap_start_tls_s() failed (uri=%s)", uri);
            return rc;
        }
    }
#endif /* LDAP_OPT_X_TLS */
    /* check if the binddn and bindpw are overwritten in the session */
    if (session->binddn[0] != '\0')
    {
#if defined(HAVE_LDAP_SASL_BIND) && defined(LDAP_SASL_SIMPLE)
        return do_ppolicy_bind(session, ld, uri);
#else /* no SASL, so no ppolicy */
        /* do a simple bind */
        log_log(LOG_DEBUG, "ldap_simple_bind_s(\"%s\",%s) (uri=\"%s\")",
                session->binddn,
                (session->bindpw[0] != '\0') ? "\"***\"" : "\"\"", uri);
        return ldap_simple_bind_s(ld, session->binddn, session->bindpw);
#endif
    }
    /* perform SASL bind if requested and available on platform */
#ifdef HAVE_LDAP_SASL_INTERACTIVE_BIND_S
    /* TODO: store this information in the session */
    if (nslcd_cfg->sasl_mech != NULL)
    {
        /* do a SASL bind */
        if (nslcd_cfg->sasl_secprops != NULL)
        {
            log_log(LOG_DEBUG,
                    "ldap_set_option(LDAP_OPT_X_SASL_SECPROPS,\"%s\")",
                    nslcd_cfg->sasl_secprops);
            LDAP_SET_OPTION(ld, LDAP_OPT_X_SASL_SECPROPS,
                            (void*)nslcd_cfg->sasl_secprops);
        }
#ifdef HAVE_SASL_INTERACT_T
        if (nslcd_cfg->binddn != NULL)
            log_log(LOG_DEBUG,
                    "ldap_sasl_interactive_bind_s(\"%s\",\"%s\") (uri=\"%s\")",
                    nslcd_cfg->binddn, nslcd_cfg->sasl_mech, uri);
        else
            log_log(LOG_DEBUG,
                    "ldap_sasl_interactive_bind_s(NULL,\"%s\") (uri=\"%s\")",
                    nslcd_cfg->sasl_mech, uri);
        return ldap_sasl_interactive_bind_s(
            ld, nslcd_cfg->binddn, nslcd_cfg->sasl_mech, NULL, NULL,
            LDAP_SASL_QUIET, do_sasl_interact, (void*)nslcd_cfg);
#else  /* HAVE_SASL_INTERACT_T */
        if (nslcd_cfg->bindpw != NULL)
        {
            cred.bv_val = nslcd_cfg->bindpw;
            cred.bv_len = strlen(nslcd_cfg->bindpw);
        }
        else
        {
            cred.bv_val = "";
            cred.bv_len = 0;
        }
        if (nslcd_cfg->binddn != NULL)
            log_log(LOG_DEBUG,
                    "ldap_sasl_bind_s(\"%s\",\"%s\",%s) (uri=\"%s\")",
                    nslcd_cfg->binddn, nslcd_cfg->sasl_mech,
                    nslcd_cfg->bindpw ? "\"***\"" : "NULL", uri);
        else
            log_log(LOG_DEBUG, "ldap_sasl_bind_s(NULL,\"%s\",%s) (uri=\"%s\")",
                    nslcd_cfg->sasl_mech,
                    nslcd_cfg->bindpw ? "\"***\"" : "NULL", uri);
        return ldap_sasl_bind_s(ld, nslcd_cfg->binddn, nslcd_cfg->sasl_mech,
                                &cred, NULL, NULL, NULL);
#endif /* not HAVE_SASL_INTERACT_T */
    }
#endif /* HAVE_LDAP_SASL_INTERACTIVE_BIND_S */
    /* do a simple bind */
    if (nslcd_cfg->binddn)
        log_log(LOG_DEBUG, "ldap_simple_bind_s(\"%s\",%s) (uri=\"%s\")",
                nslcd_cfg->binddn, nslcd_cfg->bindpw ? "\"***\"" : "NULL", uri);
    else
        log_log(LOG_DEBUG, "ldap_simple_bind_s(NULL,%s) (uri=\"%s\")",
                nslcd_cfg->bindpw ? "\"***\"" : "NULL", uri);
    return ldap_simple_bind_s(ld, nslcd_cfg->binddn, nslcd_cfg->bindpw);
}
/* This function performs the authentication phase of opening a connection.
   The binddn and bindpw parameters may be used to override the authentication
   mechanism defined in the configuration.  This returns an LDAP result
   code. */
This function performs the authentication phase of opening a connection.
The binddn and bindpw parameters may be used to override the authentication
mechanism defined in the configuration.  This returns an LDAP result
code.
This function performs the authentication phase of opening a connection . The binddn and bindpw parameters may be used to override the authentication mechanism defined in the configuration . This returns an LDAP result code .
static int do_bind(MYLDAP_SESSION* session, LDAP* ld, const char* uri)
{
    int rc;
#ifdef HAVE_LDAP_SASL_INTERACTIVE_BIND_S
#ifndef HAVE_SASL_INTERACT_T
    struct berval cred;
#endif 
#endif 
#ifdef LDAP_OPT_X_TLS
    if (nslcd_cfg->ssl == SSL_START_TLS)
    {
        log_log(LOG_DEBUG, "ldap_start_tls_s()");
        errno = 0;
        rc = ldap_start_tls_s(ld, NULL, NULL);
        if (rc != LDAP_SUCCESS)
        {
            myldap_err(LOG_WARNING, ld, rc,
                       "ldap_start_tls_s() failed (uri=%s)", uri);
            return rc;
        }
    }
#endif 
    if (session->binddn[0] != '\0')
    {
#if defined(HAVE_LDAP_SASL_BIND) && defined(LDAP_SASL_SIMPLE)
        return do_ppolicy_bind(session, ld, uri);
#else 
        log_log(LOG_DEBUG, "ldap_simple_bind_s(\"%s\",%s) (uri=\"%s\")",
                session->binddn,
                (session->bindpw[0] != '\0') ? "\"***\"" : "\"\"", uri);
        return ldap_simple_bind_s(ld, session->binddn, session->bindpw);
#endif
    }
#ifdef HAVE_LDAP_SASL_INTERACTIVE_BIND_S
    if (nslcd_cfg->sasl_mech != NULL)
    {
        if (nslcd_cfg->sasl_secprops != NULL)
        {
            log_log(LOG_DEBUG,
                    "ldap_set_option(LDAP_OPT_X_SASL_SECPROPS,\"%s\")",
                    nslcd_cfg->sasl_secprops);
            LDAP_SET_OPTION(ld, LDAP_OPT_X_SASL_SECPROPS,
                            (void*)nslcd_cfg->sasl_secprops);
        }
#ifdef HAVE_SASL_INTERACT_T
        if (nslcd_cfg->binddn != NULL)
            log_log(LOG_DEBUG,
                    "ldap_sasl_interactive_bind_s(\"%s\",\"%s\") (uri=\"%s\")",
                    nslcd_cfg->binddn, nslcd_cfg->sasl_mech, uri);
        else
            log_log(LOG_DEBUG,
                    "ldap_sasl_interactive_bind_s(NULL,\"%s\") (uri=\"%s\")",
                    nslcd_cfg->sasl_mech, uri);
        return ldap_sasl_interactive_bind_s(
            ld, nslcd_cfg->binddn, nslcd_cfg->sasl_mech, NULL, NULL,
            LDAP_SASL_QUIET, do_sasl_interact, (void*)nslcd_cfg);
#else  
        if (nslcd_cfg->bindpw != NULL)
        {
            cred.bv_val = nslcd_cfg->bindpw;
            cred.bv_len = strlen(nslcd_cfg->bindpw);
        }
        else
        {
            cred.bv_val = "";
            cred.bv_len = 0;
        }
        if (nslcd_cfg->binddn != NULL)
            log_log(LOG_DEBUG,
                    "ldap_sasl_bind_s(\"%s\",\"%s\",%s) (uri=\"%s\")",
                    nslcd_cfg->binddn, nslcd_cfg->sasl_mech,
                    nslcd_cfg->bindpw ? "\"***\"" : "NULL", uri);
        else
            log_log(LOG_DEBUG, "ldap_sasl_bind_s(NULL,\"%s\",%s) (uri=\"%s\")",
                    nslcd_cfg->sasl_mech,
                    nslcd_cfg->bindpw ? "\"***\"" : "NULL", uri);
        return ldap_sasl_bind_s(ld, nslcd_cfg->binddn, nslcd_cfg->sasl_mech,
                                &cred, NULL, NULL, NULL);
#endif 
    }
#endif 
    if (nslcd_cfg->binddn)
        log_log(LOG_DEBUG, "ldap_simple_bind_s(\"%s\",%s) (uri=\"%s\")",
                nslcd_cfg->binddn, nslcd_cfg->bindpw ? "\"***\"" : "NULL", uri);
    else
        log_log(LOG_DEBUG, "ldap_simple_bind_s(NULL,%s) (uri=\"%s\")",
                nslcd_cfg->bindpw ? "\"***\"" : "NULL", uri);
    return ldap_simple_bind_s(ld, nslcd_cfg->binddn, nslcd_cfg->bindpw);
}
static int do_bind ( MYLDAP_SESSION * session , LDAP * ld , const char * uri ) { int rc ; #ifdef HAVE_LDAP_SASL_INTERACTIVE_BIND_S #ifndef HAVE_SASL_INTERACT_T struct berval cred ; #endif #endif #ifdef LDAP_OPT_X_TLS if ( nslcd_cfg -> ssl == SSL_START_TLS ) { log_log ( LOG_DEBUG , " " ) ; errno = 0 ; rc = ldap_start_tls_s ( ld , NULL , NULL ) ; if ( rc != LDAP_SUCCESS ) { myldap_err ( LOG_WARNING , ld , rc , " " , uri ) ; return rc ; } } #endif if ( session -> binddn [ 0 ] != ' \0 ' ) { #if defined ( HAVE_LDAP_SASL_BIND ) && defined ( LDAP_SASL_SIMPLE ) return do_ppolicy_bind ( session , ld , uri ) ; #else log_log ( LOG_DEBUG , " \" \" \" \" " , session -> binddn , ( session -> bindpw [ 0 ] != ' \0 ' ) ? " \" \" " : " \" \" " , uri ) ; return ldap_simple_bind_s ( ld , session -> binddn , session -> bindpw ) ; #endif } #ifdef HAVE_LDAP_SASL_INTERACTIVE_BIND_S if ( nslcd_cfg -> sasl_mech != NULL ) { if ( nslcd_cfg -> sasl_secprops != NULL ) { log_log ( LOG_DEBUG , " \" \" " , nslcd_cfg -> sasl_secprops ) ; LDAP_SET_OPTION ( ld , LDAP_OPT_X_SASL_SECPROPS , ( void * ) nslcd_cfg -> sasl_secprops ) ; } #ifdef HAVE_SASL_INTERACT_T if ( nslcd_cfg -> binddn != NULL ) log_log ( LOG_DEBUG , " \" \" \" \" \" \" " , nslcd_cfg -> binddn , nslcd_cfg -> sasl_mech , uri ) ; else log_log ( LOG_DEBUG , " \" \" \" \" " , nslcd_cfg -> sasl_mech , uri ) ; return ldap_sasl_interactive_bind_s ( ld , nslcd_cfg -> binddn , nslcd_cfg -> sasl_mech , NULL , NULL , LDAP_SASL_QUIET , do_sasl_interact , ( void * ) nslcd_cfg ) ; #else if ( nslcd_cfg -> bindpw != NULL ) { cred . bv_val = nslcd_cfg -> bindpw ; cred . bv_len = strlen ( nslcd_cfg -> bindpw ) ; } else { cred . bv_val = " " ; cred . bv_len = 0 ; } if ( nslcd_cfg -> binddn != NULL ) log_log ( LOG_DEBUG , " \" \" \" \" \" \" " , nslcd_cfg -> binddn , nslcd_cfg -> sasl_mech , nslcd_cfg -> bindpw ? " \" \" " : " " , uri ) ; else log_log ( LOG_DEBUG , " \" \" \" \" " , nslcd_cfg -> sasl_mech , nslcd_cfg -> bindpw ? " \" \" " : " " , uri ) ; return ldap_sasl_bind_s ( ld , nslcd_cfg -> binddn , nslcd_cfg -> sasl_mech , & cred , NULL , NULL , NULL ) ; #endif } #endif if ( nslcd_cfg -> binddn ) log_log ( LOG_DEBUG , " \" \" \" \" " , nslcd_cfg -> binddn , nslcd_cfg -> bindpw ? " \" \" " : " " , uri ) ; else log_log ( LOG_DEBUG , " \" \" " , nslcd_cfg -> bindpw ? " \" \" " : " " , uri ) ; return ldap_simple_bind_s ( ld , nslcd_cfg -> binddn , nslcd_cfg -> bindpw ) ; }
This function performs the authentication phase of opening a connection.
This function performs the authentication phase of opening a connection .
/* not HAVE_SASL_INTERACT_T */ /* HAVE_LDAP_SASL_INTERACTIVE_BIND_S */ /* check if StartTLS is requested */ /* LDAP_OPT_X_TLS */ /* check if the binddn and bindpw are overwritten in the session */ /* no SASL, so no ppolicy */ /* do a simple bind */ /* perform SASL bind if requested and available on platform */ /* TODO: store this information in the session */ /* do a SASL bind */ /* HAVE_SASL_INTERACT_T */ /* not HAVE_SASL_INTERACT_T */ /* HAVE_LDAP_SASL_INTERACTIVE_BIND_S */ /* do a simple bind */