src/_bonsai/ldapconnectiter.c
static PyObject *
binding(LDAPConnectIter *self) {
    int rc;
    char buff[1];
    PyObject *value = NULL;

    DEBUG("binding [state:%d]", self->state);
    if (self->state == 3) {
        /* First call of bind. */
        rc = _ldap_bind(self->conn->ld, self->info, self->conn->ppolicy,
            NULL, &(self->message_id));
        if (rc != LDAP_SUCCESS) {
            set_exception(self->conn->ld, rc);
            return NULL;
        }
        self->state = 4;
        Py_RETURN_NONE;
    } else {
        if (self->conn->async == 0) {
            rc = WaitForSingleObject(self->info->thread, self->timeout);
        } else {
            rc = WaitForSingleObject(self->info->thread, 10);
        }
        switch (rc) {
        case WAIT_TIMEOUT:
            if (self->conn->async == 0) {
                TerminateThread(self->info->thread, -1);
                CloseHandle(self->info->thread);
                ldap_unbind_ext(self->conn->ld, NULL, NULL);
                set_exception(NULL, LDAP_TIMEOUT);
                return NULL;
            }
            Py_RETURN_NONE;
        case WAIT_OBJECT_0:
            GetExitCodeThread(self->info->thread, &rc);
            CloseHandle(self->info->thread);
            if (rc != LDAP_SUCCESS) {
                /* The ldap_connect is failed. Set a Python error. */
                set_exception(self->conn->ld, rc);
                return NULL;
            }
            if (self->conn->csock != -1) {
                /* Read and drop the data from the dummy socket. */
                if (recv(self->conn->csock, buff, 1, 0) == -1) return NULL;
                /* Dummy sockets are no longer needed. */
                self->conn->csock = -1;
                close_socketpair(self->conn->socketpair);
            }
            /* The binding is successfully finished. */
            self->state = 5;
            self->conn->closed = 0;
            if (self->conn->ppolicy == 1) {
                /* Create (result, ctrl) tuple as return value.
                   Because WinLDAP does not support password policy control,
                   it is always None. */
                value = Py_BuildValue("(O,O)", self->conn, Py_None);
                if (value == NULL) return NULL;
                return value;
            }
            else {
                Py_INCREF(self->conn);
                return (PyObject *)self->conn;
            }
        default:
            /* The thread is failed. */
            PyErr_BadInternalCall();
            return NULL;
        }
    }
}
/* Poll the answer of the separate thread that runs the binding process.
Returns NULL in case of error, Py_None for timeout, and the LDAPConnection
object if successfully finished the binding. */
Poll the answer of the separate thread that runs the binding process.
Returns NULL in case of error, Py_None for timeout, and the LDAPConnection
object if successfully finished the binding.
Poll the answer of the separate thread that runs the binding process . Returns NULL in case of error Py_None for timeout and the LDAPConnection object if successfully finished the binding .
static PyObject *
binding(LDAPConnectIter *self) {
    int rc;
    char buff[1];
    PyObject *value = NULL;
    DEBUG("binding [state:%d]", self->state);
    if (self->state == 3) {
        rc = _ldap_bind(self->conn->ld, self->info, self->conn->ppolicy,
            NULL, &(self->message_id));
        if (rc != LDAP_SUCCESS) {
            set_exception(self->conn->ld, rc);
            return NULL;
        }
        self->state = 4;
        Py_RETURN_NONE;
    } else {
        if (self->conn->async == 0) {
            rc = WaitForSingleObject(self->info->thread, self->timeout);
        } else {
            rc = WaitForSingleObject(self->info->thread, 10);
        }
        switch (rc) {
        case WAIT_TIMEOUT:
            if (self->conn->async == 0) {
                TerminateThread(self->info->thread, -1);
                CloseHandle(self->info->thread);
                ldap_unbind_ext(self->conn->ld, NULL, NULL);
                set_exception(NULL, LDAP_TIMEOUT);
                return NULL;
            }
            Py_RETURN_NONE;
        case WAIT_OBJECT_0:
            GetExitCodeThread(self->info->thread, &rc);
            CloseHandle(self->info->thread);
            if (rc != LDAP_SUCCESS) {
                set_exception(self->conn->ld, rc);
                return NULL;
            }
            if (self->conn->csock != -1) {
                if (recv(self->conn->csock, buff, 1, 0) == -1) return NULL;
                self->conn->csock = -1;
                close_socketpair(self->conn->socketpair);
            }
            self->state = 5;
            self->conn->closed = 0;
            if (self->conn->ppolicy == 1) {
                value = Py_BuildValue("(O,O)", self->conn, Py_None);
                if (value == NULL) return NULL;
                return value;
            }
            else {
                Py_INCREF(self->conn);
                return (PyObject *)self->conn;
            }
        default:
            PyErr_BadInternalCall();
            return NULL;
        }
    }
}
static PyObject * binding ( LDAPConnectIter * self ) { int rc ; char buff [ 1 ] ; PyObject * value = NULL ; DEBUG ( " " , self -> state ) ; if ( self -> state == 3 ) { rc = _ldap_bind ( self -> conn -> ld , self -> info , self -> conn -> ppolicy , NULL , & ( self -> message_id ) ) ; if ( rc != LDAP_SUCCESS ) { set_exception ( self -> conn -> ld , rc ) ; return NULL ; } self -> state = 4 ; Py_RETURN_NONE ; } else { if ( self -> conn -> async == 0 ) { rc = WaitForSingleObject ( self -> info -> thread , self -> timeout ) ; } else { rc = WaitForSingleObject ( self -> info -> thread , 10 ) ; } switch ( rc ) { case WAIT_TIMEOUT : if ( self -> conn -> async == 0 ) { TerminateThread ( self -> info -> thread , -1 ) ; CloseHandle ( self -> info -> thread ) ; ldap_unbind_ext ( self -> conn -> ld , NULL , NULL ) ; set_exception ( NULL , LDAP_TIMEOUT ) ; return NULL ; } Py_RETURN_NONE ; case WAIT_OBJECT_0 : GetExitCodeThread ( self -> info -> thread , & rc ) ; CloseHandle ( self -> info -> thread ) ; if ( rc != LDAP_SUCCESS ) { set_exception ( self -> conn -> ld , rc ) ; return NULL ; } if ( self -> conn -> csock != -1 ) { if ( recv ( self -> conn -> csock , buff , 1 , 0 ) == -1 ) return NULL ; self -> conn -> csock = -1 ; close_socketpair ( self -> conn -> socketpair ) ; } self -> state = 5 ; self -> conn -> closed = 0 ; if ( self -> conn -> ppolicy == 1 ) { value = Py_BuildValue ( " " , self -> conn , Py_None ) ; if ( value == NULL ) return NULL ; return value ; } else { Py_INCREF ( self -> conn ) ; return ( PyObject * ) self -> conn ; } default : PyErr_BadInternalCall ( ) ; return NULL ; } } }
Poll the answer of the separate thread that runs the binding process.
Poll the answer of the separate thread that runs the binding process .
/* First call of bind. */ /* The ldap_connect is failed. Set a Python error. */ /* Read and drop the data from the dummy socket. */ /* Dummy sockets are no longer needed. */ /* The binding is successfully finished. */ /* Create (result, ctrl) tuple as return value.
                   Because WinLDAP does not support password policy control,
                   it is always None. */ /* The thread is failed. */