/* * Compile action && rcode for later use. */ static int compile_action(modcallable *c, const char *attr, const char *value, const char *filename, int lineno) { int rcode, action; rcode = lrad_str2int(rcode_table, attr, -1); if (rcode < 0) { radlog(L_ERR|L_CONS, "%s[%d] Unknown module rcode '%s'.\n", filename, lineno, attr); return 0; } if (!strcasecmp(value, "return")) action = MOD_ACTION_RETURN; else if (!strcasecmp(value, "reject")) action = MOD_ACTION_REJECT; else if (strspn(value, "0123456789")==strlen(value)) { action = atoi(value); /* * Don't allow priority zero, for future use. */ if (action == 0) return 0; } else { radlog(L_ERR|L_CONS, "%s[%d] Unknown action '%s'.\n", filename, lineno, value); return 0; } c->actions[rcode] = action; return 1; }
/* * Do any per-module initialization that is separate to each * configured instance of the module. e.g. set up connections * to external databases, read configuration files, set up * dictionary entries, etc. * * If configuration information is given in the config section * that must be referenced in later calls, store a handle to it * in *instance otherwise put a null pointer there. */ static int checkval_instantiate(CONF_SECTION *conf, void **instance) { rlm_checkval_t *data; DICT_ATTR *dattr; ATTR_FLAGS flags; static const LRAD_NAME_NUMBER names[] = { { "string", PW_TYPE_STRING }, { "integer", PW_TYPE_INTEGER }, { "ipaddr", PW_TYPE_IPADDR }, { "date", PW_TYPE_DATE }, { "abinary", PW_TYPE_OCTETS }, { "octets", PW_TYPE_OCTETS }, { "binary", PW_TYPE_OCTETS }, { NULL, 0 } }; /* * Set up a storage area for instance data */ data = rad_malloc(sizeof(*data)); if (!data) { return -1; } memset(data, 0, sizeof(*data)); /* * If the configuration parameters can't be parsed, then * fail. */ if (cf_section_parse(conf, data, module_config) < 0) { checkval_detach(data); return -1; } /* * Check if data_type exists */ if (!data->data_type || !strlen(data->data_type)){ radlog(L_ERR, "rlm_checkval: Data type not defined"); checkval_detach(data); return -1; } if (!data->item_name || !strlen(data->item_name)){ radlog(L_ERR, "rlm_checkval: Item name not defined"); checkval_detach(data); return -1; } if (!data->check_name || !strlen(data->check_name)){ radlog(L_ERR, "rlm_checkval: Check item name not defined"); checkval_detach(data); return -1; } /* * Discover the attribute number of the item name */ dattr = dict_attrbyname(data->item_name); if (!dattr) { radlog(L_ERR, "rlm_checkval: No such attribute %s", data->item_name); checkval_detach(data); return -1; } data->item_attr = dattr->attr; /* * Add the check attribute name to the dictionary * if it does not already exists. dict_addattr() handles that */ memset(&flags, 0, sizeof(flags)); dict_addattr(data->check_name, 0, PW_TYPE_STRING, -1,flags); dattr = dict_attrbyname(data->check_name); if (!dattr){ radlog(L_ERR, "rlm_checkval: No such attribute %s", data->check_name); checkval_detach(data); return -1; } data->chk_attr = dattr->attr; DEBUG2("rlm_checkval: Registered name %s for attribute %d", dattr->name,dattr->attr); /* * Convert the string type to an integer type, * so we don't have to do string comparisons on each * packet. */ data->dat_type = lrad_str2int(names, data->data_type, -1); if (data->dat_type < 0) { radlog(L_ERR, "rlm_checkval: Data type %s in not known",data->data_type); checkval_detach(data); return -1; } *instance = data; return 0; }