freeradius 如何调用module 处理auth

例子

static rlm_rcode_t _test_sql_authenticate(UNUSED rlm_eap_t *inst, REQUEST *request)
{
    REQUEST *fake;
    VALUE_PAIR *vp1, *vp2;
    int rc = RLM_MODULE_FAIL;
    int idx;
    DICT_VALUE *dval;

    fake = request_alloc_fake(request);
    rad_assert(!fake->packet->vps);

    fake->packet->vps = fr_pair_list_copy(fake->packet, request->packet->vps);

    /* set the virtual server to use */
    if ((vp1 = fr_pair_find_by_num(request->config, PW_VIRTUAL_SERVER, 0, TAG_ANY)) != NULL) {
        fake->server = vp1->vp_strvalue;
    } else {
        fake->server = "check-by-controller";
    }

    /* set auth result */
    vp2 = fr_pair_find_by_num(fake->packet->vps, PW_FREERADIUS_STATS_ERROR, VENDORPEC_FREERADIUS, TAG_ANY);
    if (!vp2) {
        vp2 = fr_pair_afrom_num(fake->packet, PW_FREERADIUS_STATS_ERROR, VENDORPEC_FREERADIUS);
    }

    if (rc == RLM_MODULE_OK) {
        fr_pair_value_strcpy(vp2, "accept");
    } else {
        fr_pair_value_strcpy(vp2, "reject");
    }
    fr_pair_add(&fake->packet->vps, vp2);

    RDEBUG2("process eap_peap  authenticate at virtual server %s", fake->server);

    dval = dict_valbyname(PW_AUTH_TYPE, 0, "sql");
    idx = dval->value;
    rc = process_authenticate(idx, fake);

    /* copy the reply vps back to our reply */
    fr_pair_list_mcopy_by_num(request->reply, &request->reply->vps,
        &fake->reply->vps, 0, 0, TAG_ANY);

    talloc_free(fake);
    return rc;
}

 

posted @ 2024-08-16 17:17  codestacklinuxer  阅读(3)  评论(0编辑  收藏  举报