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_try_search(MYLDAP_SEARCH* search)
{
    int ctrlidx = 0;
    int rc;
    LDAPControl* serverctrls[3];
#ifdef HAVE_LDAP_CREATE_DEREF_CONTROL
    int i;
    struct LDAPDerefSpec ds[2];
    char* deref_attrs[2];
#endif /* HAVE_LDAP_CREATE_DEREF_CONTROL */
    int msgid;
    /* if we're using paging, build a page control */
    if ((nslcd_cfg->pagesize > 0) && (search->scope != LDAP_SCOPE_BASE))
    {
        rc = ldap_create_page_control(search->session->ld, nslcd_cfg->pagesize,
                                      search->cookie, 0, &serverctrls[ctrlidx]);
        if (rc == LDAP_SUCCESS)
            ctrlidx++;
        else
        {
            myldap_err(LOG_WARNING, search->session->ld, rc,
                       "ldap_create_page_control() failed");
            serverctrls[ctrlidx] = NULL;
            /* if we were paging, failure building the second control is fatal
             */
            if (search->cookie != NULL)
                return rc;
        }
    }
#ifdef HAVE_LDAP_CREATE_DEREF_CONTROL
    /* if doing group searches, add deref control to search request
       (this is currently a bit of a hack and hard-coded for group searches
       which are detected by requesting the attmap_group_member member
       attribute) */
    for (i = 0; search->attrs[i] != NULL; i++)
        if (strcasecmp(search->attrs[i], attmap_group_member) == 0)
        {
            /* attributes from dereff'd entries */
            deref_attrs[0] = (void*)attmap_passwd_uid;
            deref_attrs[1] = NULL;
            /* build deref control */
            ds[0].derefAttr = (void*)attmap_group_member;
            ds[0].attributes = deref_attrs;
            ds[1].derefAttr = NULL;
            ds[1].attributes = NULL;
            rc = ldap_create_deref_control(search->session->ld, ds, 0,
                                           &serverctrls[ctrlidx]);
            if (rc == LDAP_SUCCESS)
                ctrlidx++;
            else
            {
                myldap_err(LOG_WARNING, search->session->ld, rc,
                           "ldap_create_deref_control() failed");
                serverctrls[ctrlidx] = NULL;
            }
        }
#endif /* HAVE_LDAP_CREATE_DEREF_CONTROL */
    /* NULL terminate control list */
    serverctrls[ctrlidx] = NULL;
    /* clear error flag (perhaps control setting failed) */
    if (ctrlidx > 0)
    {
        rc = LDAP_SUCCESS;
        if (ldap_set_option(search->session->ld, LDAP_OPT_ERROR_NUMBER, &rc) !=
            LDAP_SUCCESS)
            log_log(LOG_WARNING, "failed to clear the error flag");
    }
    /* perform the search */
    rc = ldap_search_ext(search->session->ld, search->base, search->scope,
                         search->filter, (char**)(search->attrs), 0,
                         serverctrls[0] == NULL ? NULL : serverctrls, NULL,
                         NULL, LDAP_NO_LIMIT, &msgid);
    /* free the controls if we had them */
    for (ctrlidx = 0; serverctrls[ctrlidx] != NULL; ctrlidx++)
        ldap_control_free(serverctrls[ctrlidx]);
    /* handle errors */
    if (rc != LDAP_SUCCESS)
    {
        myldap_err(LOG_WARNING, search->session->ld, rc,
                   "ldap_search_ext() failed");
        return rc;
    }
    /* update the last activity on the connection */
    time(&(search->session->lastactivity));
    /* save msgid */
    search->msgid = msgid;
    /* return the new search */
    return LDAP_SUCCESS;
}
/* perform a search operation, the connection is assumed to be open */
perform a search operation, the connection is assumed to be open
perform a search operation the connection is assumed to be open
static int do_try_search(MYLDAP_SEARCH* search)
{
    int ctrlidx = 0;
    int rc;
    LDAPControl* serverctrls[3];
#ifdef HAVE_LDAP_CREATE_DEREF_CONTROL
    int i;
    struct LDAPDerefSpec ds[2];
    char* deref_attrs[2];
#endif 
    int msgid;
    if ((nslcd_cfg->pagesize > 0) && (search->scope != LDAP_SCOPE_BASE))
    {
        rc = ldap_create_page_control(search->session->ld, nslcd_cfg->pagesize,
                                      search->cookie, 0, &serverctrls[ctrlidx]);
        if (rc == LDAP_SUCCESS)
            ctrlidx++;
        else
        {
            myldap_err(LOG_WARNING, search->session->ld, rc,
                       "ldap_create_page_control() failed");
            serverctrls[ctrlidx] = NULL;
            if (search->cookie != NULL)
                return rc;
        }
    }
#ifdef HAVE_LDAP_CREATE_DEREF_CONTROL
    for (i = 0; search->attrs[i] != NULL; i++)
        if (strcasecmp(search->attrs[i], attmap_group_member) == 0)
        {
            deref_attrs[0] = (void*)attmap_passwd_uid;
            deref_attrs[1] = NULL;
            ds[0].derefAttr = (void*)attmap_group_member;
            ds[0].attributes = deref_attrs;
            ds[1].derefAttr = NULL;
            ds[1].attributes = NULL;
            rc = ldap_create_deref_control(search->session->ld, ds, 0,
                                           &serverctrls[ctrlidx]);
            if (rc == LDAP_SUCCESS)
                ctrlidx++;
            else
            {
                myldap_err(LOG_WARNING, search->session->ld, rc,
                           "ldap_create_deref_control() failed");
                serverctrls[ctrlidx] = NULL;
            }
        }
#endif 
    serverctrls[ctrlidx] = NULL;
    if (ctrlidx > 0)
    {
        rc = LDAP_SUCCESS;
        if (ldap_set_option(search->session->ld, LDAP_OPT_ERROR_NUMBER, &rc) !=
            LDAP_SUCCESS)
            log_log(LOG_WARNING, "failed to clear the error flag");
    }
    rc = ldap_search_ext(search->session->ld, search->base, search->scope,
                         search->filter, (char**)(search->attrs), 0,
                         serverctrls[0] == NULL ? NULL : serverctrls, NULL,
                         NULL, LDAP_NO_LIMIT, &msgid);
    for (ctrlidx = 0; serverctrls[ctrlidx] != NULL; ctrlidx++)
        ldap_control_free(serverctrls[ctrlidx]);
    if (rc != LDAP_SUCCESS)
    {
        myldap_err(LOG_WARNING, search->session->ld, rc,
                   "ldap_search_ext() failed");
        return rc;
    }
    time(&(search->session->lastactivity));
    search->msgid = msgid;
    return LDAP_SUCCESS;
}
static int do_try_search ( MYLDAP_SEARCH * search ) { int ctrlidx = 0 ; int rc ; LDAPControl * serverctrls [ 3 ] ; #ifdef HAVE_LDAP_CREATE_DEREF_CONTROL int i ; struct LDAPDerefSpec ds [ 2 ] ; char * deref_attrs [ 2 ] ; #endif int msgid ; if ( ( nslcd_cfg -> pagesize > 0 ) && ( search -> scope != LDAP_SCOPE_BASE ) ) { rc = ldap_create_page_control ( search -> session -> ld , nslcd_cfg -> pagesize , search -> cookie , 0 , & serverctrls [ ctrlidx ] ) ; if ( rc == LDAP_SUCCESS ) ctrlidx ++ ; else { myldap_err ( LOG_WARNING , search -> session -> ld , rc , " " ) ; serverctrls [ ctrlidx ] = NULL ; if ( search -> cookie != NULL ) return rc ; } } #ifdef HAVE_LDAP_CREATE_DEREF_CONTROL for ( i = 0 ; search -> attrs [ i ] != NULL ; i ++ ) if ( strcasecmp ( search -> attrs [ i ] , attmap_group_member ) == 0 ) { deref_attrs [ 0 ] = ( void * ) attmap_passwd_uid ; deref_attrs [ 1 ] = NULL ; ds [ 0 ] . derefAttr = ( void * ) attmap_group_member ; ds [ 0 ] . attributes = deref_attrs ; ds [ 1 ] . derefAttr = NULL ; ds [ 1 ] . attributes = NULL ; rc = ldap_create_deref_control ( search -> session -> ld , ds , 0 , & serverctrls [ ctrlidx ] ) ; if ( rc == LDAP_SUCCESS ) ctrlidx ++ ; else { myldap_err ( LOG_WARNING , search -> session -> ld , rc , " " ) ; serverctrls [ ctrlidx ] = NULL ; } } #endif serverctrls [ ctrlidx ] = NULL ; if ( ctrlidx > 0 ) { rc = LDAP_SUCCESS ; if ( ldap_set_option ( search -> session -> ld , LDAP_OPT_ERROR_NUMBER , & rc ) != LDAP_SUCCESS ) log_log ( LOG_WARNING , " " ) ; } rc = ldap_search_ext ( search -> session -> ld , search -> base , search -> scope , search -> filter , ( char * * ) ( search -> attrs ) , 0 , serverctrls [ 0 ] == NULL ? NULL : serverctrls , NULL , NULL , LDAP_NO_LIMIT , & msgid ) ; for ( ctrlidx = 0 ; serverctrls [ ctrlidx ] != NULL ; ctrlidx ++ ) ldap_control_free ( serverctrls [ ctrlidx ] ) ; if ( rc != LDAP_SUCCESS ) { myldap_err ( LOG_WARNING , search -> session -> ld , rc , " " ) ; return rc ; } time ( & ( search -> session -> lastactivity ) ) ; search -> msgid = msgid ; return LDAP_SUCCESS ; }
perform a search operation, the connection is assumed to be open
perform a search operation the connection is assumed to be open
/* HAVE_LDAP_CREATE_DEREF_CONTROL */ /* if we're using paging, build a page control */ /* if we were paging, failure building the second control is fatal
             */ /* if doing group searches, add deref control to search request
       (this is currently a bit of a hack and hard-coded for group searches
       which are detected by requesting the attmap_group_member member
       attribute) */ /* attributes from dereff'd entries */ /* build deref control */ /* HAVE_LDAP_CREATE_DEREF_CONTROL */ /* NULL terminate control list */ /* clear error flag (perhaps control setting failed) */ /* perform the search */ /* free the controls if we had them */ /* handle errors */ /* update the last activity on the connection */ /* save msgid */ /* return the new search */