예제 #1
0
int lp_response_bind(lp_connection_t *c, ber_int_t msgid)
{
    TRACE();

    int ret;
    ber_tag_t tag;
    ber_int_t code;
    BerElement *ber;
    ldap_data_t *data;

    if ((data = ldap_data_new()) == NULL) {
        return LP_ERR;
    }

    ber = data->ber;
    tag = LDAP_RES_BIND;
    code = 0;

    ret = ber_printf(ber, "{it{ess}}",
               msgid, tag, code, "", "");
    if (ret < 0) {
        lp_log_error("create bind response ber failed!");
        return LP_ERR;
    }
    
	lp_log_info("add a ber to reply list!");
    stk_list_add_tail(&data->list, &c->rpl_list);

    return LP_OK;
}
예제 #2
0
int stk_async_queue_push(stk_async_queue_t *queue, void *data)
{
    int ret;
    __queue_data_t *__queue_data;

    __queue_data = (__queue_data_t *)stk_palloc(queue->pool,
                                                sizeof(__queue_data_t));
    if (__queue_data == NULL) {
        return STK_ERR;
    }
    __queue_data->data = data;

    pthread_mutex_lock(&queue->mutex);
    stk_list_add_tail(&__queue_data->list, &queue->list);
    pthread_cond_broadcast(&queue->cond);
    pthread_mutex_unlock(&queue->mutex);

    return STK_OK;
}
예제 #3
0
static int __search_failed(lp_task_t *task, lp_connection_t *c)
{
    lp_assert(task != NULL);
    int         ret;
    int         msgid;
    int         code;
    ber_tag_t   tag;
    BerElement *ber;

    tag  = LDAP_RES_SEARCH_RESULT;
    /*
     * ironport's query base domain is aways right, mysql query
     * failed, just return no search entry with an success query
     * done ber
     * code = LDAP_NO_SUCH_OBJECT means base domain no exist;
     */
    code = LDAP_SUCCESS;


    mysql_msg_t *reply = (mysql_msg_t *)task->data;
    msgid = reply->msgid;

    ldap_data_t *reply_data = ldap_data_new();
    if (reply_data == NULL) {
        lp_log_error("create reply_data failed!");
        return LP_ERR;
    }

    ber = reply_data->ber;

    ret = ber_printf(ber, "{it{ess}}", msgid, tag, code, "", "");
    if (ret == LBER_ERROR) {
        lp_log_error("create search done ber failed!");
        return LP_ERR;
    }

    stk_list_add_tail(&reply_data->list, &c->rpl_list);

    return LP_OK;
}
예제 #4
0
static int __search_succeed(lp_task_t *task, lp_connection_t *c)
{
    TRACE();

    int msgid;
    BerElement *ber;
    ber_tag_t tag;
    int code;
    struct berval objectName;
    int ret;

    mysql_msg_t *reply = (mysql_msg_t *)task->data;
    msgid = reply->msgid;


    ldap_data_t *reply_data = ldap_data_new();
    if (reply_data == NULL) {
        lp_log_error("create reply_data failed!");
        return LP_ERR;
    }
    ber = reply_data->ber;

    tag = LDAP_RES_SEARCH_ENTRY;
    struct berval type = {11, "objectClass"};
    struct berval type_vals1 = {8, "dcObject"};
    struct berval type_vals2 = {12, "organization"};

    if (reply->filter_type == LDAP_FILTER_EQUALITY) {
        char dn[LP_DN_LEN + 1] = {0};
        /* mail is a partialAttribute */
        struct berval attr;
        struct berval attr_val;

        ret = snprintf(dn, LP_DN_LEN, "%s=%s,%s", reply->equalityMatch.attribute,
                                   reply->equalityMatch.assertionValue,
                                   reply->base);
        objectName.bv_len = ret;
        objectName.bv_val = stk_pcalloc(task->pool, objectName.bv_len);
        strncpy(objectName.bv_val, dn, objectName.bv_len);

        attr.bv_len = strlen(reply->equalityMatch.attribute);
        attr.bv_val = stk_pcalloc(task->pool, attr.bv_len);
        strncpy(attr.bv_val, reply->equalityMatch.attribute, attr.bv_len);

        attr_val.bv_len = strlen(reply->equalityMatch.assertionValue);
        attr_val.bv_val = stk_pcalloc(task->pool, attr_val.bv_len);
        strncpy(attr_val.bv_val, reply->equalityMatch.assertionValue, attr_val.bv_len);

        ret = ber_printf(ber, "{it{O{{O[O]}{O[OO]}}}}", msgid, tag, &objectName,
                               &attr, &attr_val, &type, &type_vals1, &type_vals2);

    } else {
        char *entry = reply->base;
        lp_assert(entry != NULL);
        objectName.bv_len = strlen(entry);
        objectName.bv_val = stk_pcalloc(task->pool, objectName.bv_len);
        strncpy(objectName.bv_val, entry, objectName.bv_len);
        ret = ber_printf(ber, "{it{O{{O[OO]}}}}", msgid, tag, &objectName,
                               &type, &type_vals1, &type_vals2);
    }
    if (ret == LBER_ERROR) {
        ldap_data_destroy(reply_data);
        lp_log_error("create search entry ber failed!");
        return LP_ERR;
    }

    /* 
     * note if the result entries just have one,
     * this is right, otherwise is fault.
     */
    tag  = LDAP_RES_SEARCH_RESULT;
    code = LDAP_SUCCESS;
    ret = ber_printf(ber, "{it{ess}}", msgid, tag, code, "", "");
    if (ret == LBER_ERROR) {
        lp_log_error("create search done ber failed!");
        return LP_ERR;
    }

    stk_list_add_tail(&reply_data->list, &c->rpl_list);
    
    return LP_OK;
}