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_set_options(MYLDAP_SESSION* session)
{
    int rc;
    struct timeval tv;
#ifdef LDAP_OPT_CONNECT_CB
    /* make this static because OpenLDAP doesn't make its own copy */
    static struct ldap_conncb cb;
#endif /* LDAP_OPT_CONNECT_CB */
#ifdef LDAP_OPT_X_TLS
    int i;
#endif /* LDAP_OPT_X_TLS */
#ifdef HAVE_LDAP_SET_REBIND_PROC
    /* the rebind function that is called when chasing referrals, see
       http://publib.boulder.ibm.com/infocenter/iseries/v5r3/topic/apis/ldap_set_rebind_proc.htm
       http://www.openldap.org/software/man.cgi?query=ldap_set_rebind_proc&manpath=OpenLDAP+2.4-Release
     */
    /* TODO: probably only set this if we should chase referrals */
    log_log(LOG_DEBUG, "ldap_set_rebind_proc()");
#ifndef LDAP_SET_REBIND_PROC_RETURNS_VOID /* it returns int */
    rc = ldap_set_rebind_proc(session->ld, do_rebind, session);
    if (rc != LDAP_SUCCESS)
    {
        myldap_err(LOG_ERR, session->ld, rc, "ldap_set_rebind_proc() failed");
        return rc;
    }
#else /* ldap_set_rebind_proc() returns void */
    ldap_set_rebind_proc(session->ld, do_rebind, session);
#endif
#endif /* HAVE_LDAP_SET_REBIND_PROC */
    /* set the protocol version to use */
    log_log(LOG_DEBUG, "ldap_set_option(LDAP_OPT_PROTOCOL_VERSION,%d)",
            nslcd_cfg->ldap_version);
    LDAP_SET_OPTION(session->ld, LDAP_OPT_PROTOCOL_VERSION,
                    &nslcd_cfg->ldap_version);
    /* set some other options */
    log_log(LOG_DEBUG, "ldap_set_option(LDAP_OPT_DEREF,%d)", nslcd_cfg->deref);
    LDAP_SET_OPTION(session->ld, LDAP_OPT_DEREF, &nslcd_cfg->deref);
    log_log(LOG_DEBUG, "ldap_set_option(LDAP_OPT_TIMELIMIT,%d)",
            nslcd_cfg->timelimit);
    LDAP_SET_OPTION(session->ld, LDAP_OPT_TIMELIMIT, &nslcd_cfg->timelimit);
    tv.tv_sec = nslcd_cfg->bind_timelimit;
    tv.tv_usec = 0;
#ifdef LDAP_OPT_TIMEOUT
    log_log(LOG_DEBUG, "ldap_set_option(LDAP_OPT_TIMEOUT,%d)",
            nslcd_cfg->timelimit);
    LDAP_SET_OPTION(session->ld, LDAP_OPT_TIMEOUT, &tv);
#endif /* LDAP_OPT_TIMEOUT */
#ifdef LDAP_OPT_NETWORK_TIMEOUT
    log_log(LOG_DEBUG, "ldap_set_option(LDAP_OPT_NETWORK_TIMEOUT,%d)",
            nslcd_cfg->timelimit);
    LDAP_SET_OPTION(session->ld, LDAP_OPT_NETWORK_TIMEOUT, &tv);
#endif /* LDAP_OPT_NETWORK_TIMEOUT */
#ifdef LDAP_X_OPT_CONNECT_TIMEOUT
    log_log(LOG_DEBUG, "ldap_set_option(LDAP_X_OPT_CONNECT_TIMEOUT,%d)",
            nslcd_cfg->timelimit);
    LDAP_SET_OPTION(session->ld, LDAP_X_OPT_CONNECT_TIMEOUT, &tv);
#endif /* LDAP_X_OPT_CONNECT_TIMEOUT */
    log_log(LOG_DEBUG, "ldap_set_option(LDAP_OPT_REFERRALS,%s)",
            nslcd_cfg->referrals ? "LDAP_OPT_ON" : "LDAP_OPT_OFF");
    LDAP_SET_OPTION(session->ld, LDAP_OPT_REFERRALS,
                    nslcd_cfg->referrals ? LDAP_OPT_ON : LDAP_OPT_OFF);
    log_log(LOG_DEBUG, "ldap_set_option(LDAP_OPT_RESTART,LDAP_OPT_ON)");
    LDAP_SET_OPTION(session->ld, LDAP_OPT_RESTART, LDAP_OPT_ON);
#ifdef LDAP_OPT_CONNECT_CB
    /* register a connection callback */
    cb.lc_add = connect_cb;
    cb.lc_del = disconnect_cb;
    cb.lc_arg = NULL;
    LDAP_SET_OPTION(session->ld, LDAP_OPT_CONNECT_CB, (void*)&cb);
#endif /* LDAP_OPT_CONNECT_CB */
#ifdef LDAP_OPT_X_TLS
    /* if SSL is desired, then enable it */
    if ((nslcd_cfg->ssl == SSL_LDAPS) ||
        (strncasecmp(nslcd_cfg->uris[session->current_uri].uri, "ldaps://",
                     8) == 0))
    {
        /* use tls */
        i = LDAP_OPT_X_TLS_HARD;
        log_log(LOG_DEBUG,
                "ldap_set_option(LDAP_OPT_X_TLS,LDAP_OPT_X_TLS_HARD)");
        LDAP_SET_OPTION(session->ld, LDAP_OPT_X_TLS, &i);
    }
#endif /* LDAP_OPT_X_TLS */
#ifdef LDAP_OPT_X_SASL_NOCANON
    if (nslcd_cfg->sasl_canonicalize >= 0)
    {
        log_log(LOG_DEBUG, "ldap_set_option(LDAP_OPT_X_SASL_NOCANON,%s)",
                nslcd_cfg->sasl_canonicalize ? "LDAP_OPT_OFF" : "LDAP_OPT_ON");
        LDAP_SET_OPTION(session->ld, LDAP_OPT_X_SASL_NOCANON,
                        nslcd_cfg->sasl_canonicalize ? LDAP_OPT_OFF
                                                     : LDAP_OPT_ON);
    }
#endif /* LDAP_OPT_X_SASL_NOCANON */
    /* if nothing above failed, everything should be fine */
    return LDAP_SUCCESS;
}
/* This function sets a number of properties on the connection, based
   what is configured in the configfile. This function returns an
   LDAP status code. */
This function sets a number of properties on the connection, based
what is configured in the configfile. This function returns an
LDAP status code.
This function sets a number of properties on the connection based what is configured in the configfile . This function returns an LDAP status code .
static int do_set_options(MYLDAP_SESSION* session)
{
    int rc;
    struct timeval tv;
#ifdef LDAP_OPT_CONNECT_CB
    static struct ldap_conncb cb;
#endif 
#ifdef LDAP_OPT_X_TLS
    int i;
#endif 
#ifdef HAVE_LDAP_SET_REBIND_PROC
    log_log(LOG_DEBUG, "ldap_set_rebind_proc()");
#ifndef LDAP_SET_REBIND_PROC_RETURNS_VOID 
    rc = ldap_set_rebind_proc(session->ld, do_rebind, session);
    if (rc != LDAP_SUCCESS)
    {
        myldap_err(LOG_ERR, session->ld, rc, "ldap_set_rebind_proc() failed");
        return rc;
    }
#else 
    ldap_set_rebind_proc(session->ld, do_rebind, session);
#endif
#endif 
    log_log(LOG_DEBUG, "ldap_set_option(LDAP_OPT_PROTOCOL_VERSION,%d)",
            nslcd_cfg->ldap_version);
    LDAP_SET_OPTION(session->ld, LDAP_OPT_PROTOCOL_VERSION,
                    &nslcd_cfg->ldap_version);
    log_log(LOG_DEBUG, "ldap_set_option(LDAP_OPT_DEREF,%d)", nslcd_cfg->deref);
    LDAP_SET_OPTION(session->ld, LDAP_OPT_DEREF, &nslcd_cfg->deref);
    log_log(LOG_DEBUG, "ldap_set_option(LDAP_OPT_TIMELIMIT,%d)",
            nslcd_cfg->timelimit);
    LDAP_SET_OPTION(session->ld, LDAP_OPT_TIMELIMIT, &nslcd_cfg->timelimit);
    tv.tv_sec = nslcd_cfg->bind_timelimit;
    tv.tv_usec = 0;
#ifdef LDAP_OPT_TIMEOUT
    log_log(LOG_DEBUG, "ldap_set_option(LDAP_OPT_TIMEOUT,%d)",
            nslcd_cfg->timelimit);
    LDAP_SET_OPTION(session->ld, LDAP_OPT_TIMEOUT, &tv);
#endif 
#ifdef LDAP_OPT_NETWORK_TIMEOUT
    log_log(LOG_DEBUG, "ldap_set_option(LDAP_OPT_NETWORK_TIMEOUT,%d)",
            nslcd_cfg->timelimit);
    LDAP_SET_OPTION(session->ld, LDAP_OPT_NETWORK_TIMEOUT, &tv);
#endif 
#ifdef LDAP_X_OPT_CONNECT_TIMEOUT
    log_log(LOG_DEBUG, "ldap_set_option(LDAP_X_OPT_CONNECT_TIMEOUT,%d)",
            nslcd_cfg->timelimit);
    LDAP_SET_OPTION(session->ld, LDAP_X_OPT_CONNECT_TIMEOUT, &tv);
#endif 
    log_log(LOG_DEBUG, "ldap_set_option(LDAP_OPT_REFERRALS,%s)",
            nslcd_cfg->referrals ? "LDAP_OPT_ON" : "LDAP_OPT_OFF");
    LDAP_SET_OPTION(session->ld, LDAP_OPT_REFERRALS,
                    nslcd_cfg->referrals ? LDAP_OPT_ON : LDAP_OPT_OFF);
    log_log(LOG_DEBUG, "ldap_set_option(LDAP_OPT_RESTART,LDAP_OPT_ON)");
    LDAP_SET_OPTION(session->ld, LDAP_OPT_RESTART, LDAP_OPT_ON);
#ifdef LDAP_OPT_CONNECT_CB
    cb.lc_add = connect_cb;
    cb.lc_del = disconnect_cb;
    cb.lc_arg = NULL;
    LDAP_SET_OPTION(session->ld, LDAP_OPT_CONNECT_CB, (void*)&cb);
#endif 
#ifdef LDAP_OPT_X_TLS
    if ((nslcd_cfg->ssl == SSL_LDAPS) ||
        (strncasecmp(nslcd_cfg->uris[session->current_uri].uri, "ldaps://",
                     8) == 0))
    {
        i = LDAP_OPT_X_TLS_HARD;
        log_log(LOG_DEBUG,
                "ldap_set_option(LDAP_OPT_X_TLS,LDAP_OPT_X_TLS_HARD)");
        LDAP_SET_OPTION(session->ld, LDAP_OPT_X_TLS, &i);
    }
#endif 
#ifdef LDAP_OPT_X_SASL_NOCANON
    if (nslcd_cfg->sasl_canonicalize >= 0)
    {
        log_log(LOG_DEBUG, "ldap_set_option(LDAP_OPT_X_SASL_NOCANON,%s)",
                nslcd_cfg->sasl_canonicalize ? "LDAP_OPT_OFF" : "LDAP_OPT_ON");
        LDAP_SET_OPTION(session->ld, LDAP_OPT_X_SASL_NOCANON,
                        nslcd_cfg->sasl_canonicalize ? LDAP_OPT_OFF
                                                     : LDAP_OPT_ON);
    }
#endif 
    return LDAP_SUCCESS;
}
static int do_set_options ( MYLDAP_SESSION * session ) { int rc ; struct timeval tv ; #ifdef LDAP_OPT_CONNECT_CB static struct ldap_conncb cb ; #endif #ifdef LDAP_OPT_X_TLS int i ; #endif #ifdef HAVE_LDAP_SET_REBIND_PROC log_log ( LOG_DEBUG , " " ) ; #ifndef LDAP_SET_REBIND_PROC_RETURNS_VOID rc = ldap_set_rebind_proc ( session -> ld , do_rebind , session ) ; if ( rc != LDAP_SUCCESS ) { myldap_err ( LOG_ERR , session -> ld , rc , " " ) ; return rc ; } #else ldap_set_rebind_proc ( session -> ld , do_rebind , session ) ; #endif #endif log_log ( LOG_DEBUG , " " , nslcd_cfg -> ldap_version ) ; LDAP_SET_OPTION ( session -> ld , LDAP_OPT_PROTOCOL_VERSION , & nslcd_cfg -> ldap_version ) ; log_log ( LOG_DEBUG , " " , nslcd_cfg -> deref ) ; LDAP_SET_OPTION ( session -> ld , LDAP_OPT_DEREF , & nslcd_cfg -> deref ) ; log_log ( LOG_DEBUG , " " , nslcd_cfg -> timelimit ) ; LDAP_SET_OPTION ( session -> ld , LDAP_OPT_TIMELIMIT , & nslcd_cfg -> timelimit ) ; tv . tv_sec = nslcd_cfg -> bind_timelimit ; tv . tv_usec = 0 ; #ifdef LDAP_OPT_TIMEOUT log_log ( LOG_DEBUG , " " , nslcd_cfg -> timelimit ) ; LDAP_SET_OPTION ( session -> ld , LDAP_OPT_TIMEOUT , & tv ) ; #endif #ifdef LDAP_OPT_NETWORK_TIMEOUT log_log ( LOG_DEBUG , " " , nslcd_cfg -> timelimit ) ; LDAP_SET_OPTION ( session -> ld , LDAP_OPT_NETWORK_TIMEOUT , & tv ) ; #endif #ifdef LDAP_X_OPT_CONNECT_TIMEOUT log_log ( LOG_DEBUG , " " , nslcd_cfg -> timelimit ) ; LDAP_SET_OPTION ( session -> ld , LDAP_X_OPT_CONNECT_TIMEOUT , & tv ) ; #endif log_log ( LOG_DEBUG , " " , nslcd_cfg -> referrals ? " " : " " ) ; LDAP_SET_OPTION ( session -> ld , LDAP_OPT_REFERRALS , nslcd_cfg -> referrals ? LDAP_OPT_ON : LDAP_OPT_OFF ) ; log_log ( LOG_DEBUG , " " ) ; LDAP_SET_OPTION ( session -> ld , LDAP_OPT_RESTART , LDAP_OPT_ON ) ; #ifdef LDAP_OPT_CONNECT_CB cb . lc_add = connect_cb ; cb . lc_del = disconnect_cb ; cb . lc_arg = NULL ; LDAP_SET_OPTION ( session -> ld , LDAP_OPT_CONNECT_CB , ( void * ) & cb ) ; #endif #ifdef LDAP_OPT_X_TLS if ( ( nslcd_cfg -> ssl == SSL_LDAPS ) || ( strncasecmp ( nslcd_cfg -> uris [ session -> current_uri ] . uri , " " , 8 ) == 0 ) ) { i = LDAP_OPT_X_TLS_HARD ; log_log ( LOG_DEBUG , " " ) ; LDAP_SET_OPTION ( session -> ld , LDAP_OPT_X_TLS , & i ) ; } #endif #ifdef LDAP_OPT_X_SASL_NOCANON if ( nslcd_cfg -> sasl_canonicalize >= 0 ) { log_log ( LOG_DEBUG , " " , nslcd_cfg -> sasl_canonicalize ? " " : " " ) ; LDAP_SET_OPTION ( session -> ld , LDAP_OPT_X_SASL_NOCANON , nslcd_cfg -> sasl_canonicalize ? LDAP_OPT_OFF : LDAP_OPT_ON ) ; } #endif return LDAP_SUCCESS ; }
This function sets a number of properties on the connection, based
what is configured in the configfile.
This function sets a number of properties on the connection based what is configured in the configfile .
/* make this static because OpenLDAP doesn't make its own copy */ /* LDAP_OPT_CONNECT_CB */ /* LDAP_OPT_X_TLS */ /* the rebind function that is called when chasing referrals, see
       http://publib.boulder.ibm.com/infocenter/iseries/v5r3/topic/apis/ldap_set_rebind_proc.htm
       http://www.openldap.org/software/man.cgi?query=ldap_set_rebind_proc&manpath=OpenLDAP+2.4-Release
     */ /* TODO: probably only set this if we should chase referrals */ /* it returns int */ /* ldap_set_rebind_proc() returns void */ /* HAVE_LDAP_SET_REBIND_PROC */ /* set the protocol version to use */ /* set some other options */ /* LDAP_OPT_TIMEOUT */ /* LDAP_OPT_NETWORK_TIMEOUT */ /* LDAP_X_OPT_CONNECT_TIMEOUT */ /* register a connection callback */ /* LDAP_OPT_CONNECT_CB */ /* if SSL is desired, then enable it */ /* use tls */ /* LDAP_OPT_X_TLS */ /* LDAP_OPT_X_SASL_NOCANON */ /* if nothing above failed, everything should be fine */