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_open(MYLDAP_SESSION* session)
{
    int rc;
    /* if the connection is still there (ie. ldap_unbind() wasn't
       called) then we can return the cached connection */
    if (session->ld != NULL)
        return LDAP_SUCCESS;
    /* we should build a new session now */
    session->ld = NULL;
    session->lastactivity = 0;
    /* open the connection */
    log_log(LOG_DEBUG, "ldap_initialize(%s)",
            nslcd_cfg->uris[session->current_uri].uri);
    errno = 0;
    rc = ldap_initialize(&(session->ld),
                         nslcd_cfg->uris[session->current_uri].uri);
    if (rc != LDAP_SUCCESS)
    {
        myldap_err(LOG_WARNING, session->ld, rc, "ldap_initialize(%s) failed",
                   nslcd_cfg->uris[session->current_uri].uri);
        if (session->ld != NULL)
            do_close(session);
        return rc;
    }
    else if (session->ld == NULL)
    {
        log_log(LOG_WARNING, "ldap_initialize() returned NULL");
        return LDAP_LOCAL_ERROR;
    }
    /* set the options for the connection */
    rc = do_set_options(session);
    if (rc != LDAP_SUCCESS)
    {
        do_close(session);
        return rc;
    }
    /* bind to the server */
    errno = 0;
    rc = do_bind(session, session->ld,
                 nslcd_cfg->uris[session->current_uri].uri);
    if (rc != LDAP_SUCCESS)
    {
        /* log actual LDAP error code */
        myldap_err((session->binddn[0] == '\0') ? LOG_WARNING : LOG_DEBUG,
                   session->ld, rc, "failed to bind to LDAP server %s",
                   nslcd_cfg->uris[session->current_uri].uri);
        do_close(session);
        return rc;
    }
    /* update last activity and finish off state */
    time(&(session->lastactivity));
    return LDAP_SUCCESS;
}
/* This opens connection to an LDAP server, sets all connection options
   and binds to the server. This returns an LDAP status code. */
This opens connection to an LDAP server, sets all connection options
and binds to the server. This returns an LDAP status code.
This opens connection to an LDAP server sets all connection options and binds to the server . This returns an LDAP status code .
static int do_open(MYLDAP_SESSION* session)
{
    int rc;
    if (session->ld != NULL)
        return LDAP_SUCCESS;
    session->ld = NULL;
    session->lastactivity = 0;
    log_log(LOG_DEBUG, "ldap_initialize(%s)",
            nslcd_cfg->uris[session->current_uri].uri);
    errno = 0;
    rc = ldap_initialize(&(session->ld),
                         nslcd_cfg->uris[session->current_uri].uri);
    if (rc != LDAP_SUCCESS)
    {
        myldap_err(LOG_WARNING, session->ld, rc, "ldap_initialize(%s) failed",
                   nslcd_cfg->uris[session->current_uri].uri);
        if (session->ld != NULL)
            do_close(session);
        return rc;
    }
    else if (session->ld == NULL)
    {
        log_log(LOG_WARNING, "ldap_initialize() returned NULL");
        return LDAP_LOCAL_ERROR;
    }
    rc = do_set_options(session);
    if (rc != LDAP_SUCCESS)
    {
        do_close(session);
        return rc;
    }
    errno = 0;
    rc = do_bind(session, session->ld,
                 nslcd_cfg->uris[session->current_uri].uri);
    if (rc != LDAP_SUCCESS)
    {
        myldap_err((session->binddn[0] == '\0') ? LOG_WARNING : LOG_DEBUG,
                   session->ld, rc, "failed to bind to LDAP server %s",
                   nslcd_cfg->uris[session->current_uri].uri);
        do_close(session);
        return rc;
    }
    time(&(session->lastactivity));
    return LDAP_SUCCESS;
}
static int do_open ( MYLDAP_SESSION * session ) { int rc ; if ( session -> ld != NULL ) return LDAP_SUCCESS ; session -> ld = NULL ; session -> lastactivity = 0 ; log_log ( LOG_DEBUG , " " , nslcd_cfg -> uris [ session -> current_uri ] . uri ) ; errno = 0 ; rc = ldap_initialize ( & ( session -> ld ) , nslcd_cfg -> uris [ session -> current_uri ] . uri ) ; if ( rc != LDAP_SUCCESS ) { myldap_err ( LOG_WARNING , session -> ld , rc , " " , nslcd_cfg -> uris [ session -> current_uri ] . uri ) ; if ( session -> ld != NULL ) do_close ( session ) ; return rc ; } else if ( session -> ld == NULL ) { log_log ( LOG_WARNING , " " ) ; return LDAP_LOCAL_ERROR ; } rc = do_set_options ( session ) ; if ( rc != LDAP_SUCCESS ) { do_close ( session ) ; return rc ; } errno = 0 ; rc = do_bind ( session , session -> ld , nslcd_cfg -> uris [ session -> current_uri ] . uri ) ; if ( rc != LDAP_SUCCESS ) { myldap_err ( ( session -> binddn [ 0 ] == ' \0 ' ) ? LOG_WARNING : LOG_DEBUG , session -> ld , rc , " " , nslcd_cfg -> uris [ session -> current_uri ] . uri ) ; do_close ( session ) ; return rc ; } time ( & ( session -> lastactivity ) ) ; return LDAP_SUCCESS ; }
This opens connection to an LDAP server, sets all connection options
and binds to the server.
This opens connection to an LDAP server sets all connection options and binds to the server .
/* if the connection is still there (ie. ldap_unbind() wasn't
       called) then we can return the cached connection */ /* we should build a new session now */ /* open the connection */ /* set the options for the connection */ /* bind to the server */ /* log actual LDAP error code */ /* update last activity and finish off state */