I have something like this on 'radiusd.conf':

...
modules{ ...
   pgping {
   }
...
}
...

Where 'rlm_pgping' is a module compiled and installed following the manual. My question is why does it not appear to load (i.e. not showing any messages with 'radiusd -X')? _the module code is on the end of the message_
I have other custom modules that works fine.
Am I doing something wrong?

On the other hand, I've been playing around with 'radiusd.conf' I've discovered that if I add some random module name in the module instantiation section, radiusd doesn't complain at all about it's non-existence! This is a little inconvenient.

Thanks in advance,
---
Tomás A. Rossi
Ministerio de Economía
Proyecto de Informática
Buenos Aires, Argentina

/*
 * rlm_pgping.c
 *
 * Este módulo se encarga de "pinguear" la base de datos primaria e informa si
 * la misma está caída (FAIL) o funcionando normalmente (OK).
 */

#include "autoconf.h"
#include "libradius.h"

#include <stdio.h>
#include <stdlib.h>

#include "radiusd.h"
#include "modules.h"
#include "conffile.h"
#include "libpq-fe.h"

/*
 * Estructura para la configuración del módulo.
 */
typedef struct rlm_pgping_t {
        char            *host;
        char            *dbname;
        char            *user;
        char            *password;
        char            *port;
        int             timeout;
} rlm_pgping_t;

/*
 * No hay parámetros de configuración.
 */
static CONF_PARSER module_config[] = {
  { "string", PW_TYPE_STRING_PTR,
    offsetof(rlm_pgping_t,host), NULL, "localhost" },
  { "string", PW_TYPE_STRING_PTR,
    offsetof(rlm_pgping_t,dbname), NULL, "" },
  { "string", PW_TYPE_STRING_PTR,
    offsetof(rlm_pgping_t,user), NULL, "" },
  { "string", PW_TYPE_STRING_PTR,
    offsetof(rlm_pgping_t,password), NULL, "" },
  { "string", PW_TYPE_STRING_PTR,
    offsetof(rlm_pgping_t,port), NULL, "" },
  { "integer", PW_TYPE_INTEGER,
    offsetof(rlm_pgping_t,timeout), NULL, "30" },

  { NULL, -1, 0, NULL, NULL }           /* end the list */
};

static int mandar_pgping(void *inst, REQUEST *req)
{
 char condata[256];     /* Buffer para guardar los datos de conexión. */
 PGconn *con;           /* Conexión a la base. */

 DEBUG("PGPING: Empieza el modulo");

 /*req = req;*/

 #define INST ((rlm_pgping_t *)inst)

 snprintf(condata, sizeof(condata)-1, "host=%s port=%s dbname=%s user=%s "
                "password='%s' connect_timeout=%d", INST->host, INST->port,
                INST->dbname, INST->user, INST->password, INST->timeout);
 con = PQconnectdb(condata);

 DEBUG("Intentando conectar a la base primaria con datos de conexión: '%s'",
                condata);
 if (PQstatus(con) == CONNECTION_BAD) {
        radlog(L_AUTH, "Falló la conexión a la base primaria.");
        return RLM_MODULE_FAIL;
 }

 return RLM_MODULE_OK;
}

static int pgping_init(void)
{
 return 0;
}

/*
 * Hay que leer los parámetros de configuración para la instancia.
 */
static int pgping_instantiate(CONF_SECTION *conf, void **instance)
{
 rlm_pgping_t *conf_data;

 /*
  * Pedir memoria para los parámetros de configuración.
  */
 conf_data = rad_malloc(sizeof(*conf_data));
 if (!conf_data) {
        return RLM_MODULE_FAIL;
 }
 memset(conf_data, 0, sizeof(*conf_data));

 /*
  * Si falla el "parseo" del archivo de configuración para el módulo, CHAU!.
  */
 if (cf_section_parse(conf, conf_data, module_config) < 0) {
        free(conf_data);
        return RLM_MODULE_FAIL;
 }

 *instance = conf_data;

 return RLM_MODULE_OK;
}

static int pgping_detach(void *inst)
{
 free(INST->host);
 free(INST->port);
 free(INST->dbname);
 free(INST->user);
 free(INST->password);
 free(inst);

 return 0;
}

/*
 *      The module name should be the only globally exported symbol.
 *      That is, everything else should be 'static'.
 *
 *      If the module needs to temporarily modify it's instantiation
 *      data, the type should be changed to RLM_TYPE_THREAD_UNSAFE.
 *      The server will then take care of ensuring that the module
 *      is single-threaded.
 */
module_t rlm_pgping = {
        "pgping",
        RLM_TYPE_THREAD_SAFE,           /* type */
        pgping_init,                    /* initialization */
        pgping_instantiate,             /* instantiation */
        {
                mandar_pgping,          /* authentication */
                mandar_pgping,          /* authorization */
                mandar_pgping,          /* preaccounting */
                mandar_pgping,          /* accounting */
                NULL,                   /* checksimul */
                NULL,                   /* pre-proxy */
                NULL,                   /* post-proxy */
                NULL                    /* post-auth */
        },
        pgping_detach,                  /* detach */
        NULL,                           /* destroy */
};
- 
List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html

Reply via email to