33 RCSID(
"$Id: 43a8c1530a9eacca900f9e579e742f676dc55efc $")
35 #include <freeradius-devel/radiusd.h>
36 #include <freeradius-devel/modules.h>
58 #define RLM_RUBY_STRUCT(foo) unsigned long func_##foo
106 status = FIX2INT(msg_type);
107 msg = StringValuePtr(rb_msg);
108 radlog(status,
"%s", msg);
115 char const *function_name) {
121 if (NIL_P(rb_value)) {
125 if (TYPE(rb_value) != T_ARRAY) {
126 REDEBUG(
"add_vp_tuple, %s: non-array passed", function_name);
131 outertuplesize = RARRAY_LEN(rb_value);
133 for (i = 0; i < outertuplesize; i++) {
134 VALUE pTupleElement = rb_ary_entry(rb_value, i);
136 if ((pTupleElement != 0) &&
137 (TYPE(pTupleElement) == T_ARRAY)) {
142 if ((tuplesize = RARRAY_LEN(pTupleElement)) != 2) {
143 REDEBUG(
"%s: tuple element %i is a tuple "
144 " of size %li. must be 2\n", function_name,
147 VALUE pString1, pString2;
149 pString1 = rb_ary_entry(pTupleElement, 0);
150 pString2 = rb_ary_entry(pTupleElement, 1);
152 if ((TYPE(pString1) == T_STRING) &&
153 (TYPE(pString2) == T_STRING)) {
162 s1 = StringValuePtr(pString1);
163 s2 = StringValuePtr(pString2);
165 if ((s1 != NULL) && (s2 != NULL)) {
166 DEBUG(
"%s: %s = %s ",
167 function_name, s1, s2);
172 DEBUG(
"%s: s1, s2 OK", function_name);
174 DEBUG(
"%s: s1, s2 FAILED", function_name);
177 REDEBUG(
"%s: string conv failed", function_name);
181 REDEBUG(
"%s: tuple element %d must be "
182 "(string, string)", function_name, i);
186 REDEBUG(
"%s: tuple element %d is not a tuple\n",
198 #define BUF_SIZE 1024
200 VALUE module,
char const *function_name)
208 VALUE rb_request, rb_result, rb_reply_items, rb_config, rbString1, rbString2;
211 DEBUG(
"Calling ruby function %s which has id: %lu\n", function_name, func);
233 rb_request = rb_ary_new2(n_tuple);
239 VALUE tmp = rb_ary_new2(2);
247 rbString1 = rb_str_new2(buf);
249 rbString2 = rb_str_new2(buf);
251 rb_ary_push(tmp, rbString1);
252 rb_ary_push(tmp, rbString2);
253 rb_ary_push(rb_request, tmp);
258 rb_result = rb_funcall(module, func, 1, rb_request);
265 if (TYPE(rb_result) == T_ARRAY) {
266 if (!FIXNUM_P(rb_ary_entry(rb_result, 0))) {
267 ERROR(
"First element of an array was not a FIXNUM (Which has to be a return_value)");
273 rcode = FIX2INT(rb_ary_entry(rb_result, 0));
279 rb_reply_items = rb_ary_entry(rb_result, 1);
280 rb_config = rb_ary_entry(rb_result, 2);
282 add_vp_tuple(request->reply, request, &request->reply->vps,
283 rb_reply_items, function_name);
285 rb_config, function_name);
287 }
else if (FIXNUM_P(rb_result)) {
288 rcode = FIX2INT(rb_result);
320 static int load_function(
char const *f_name,
unsigned long *func, VALUE module) {
324 *func = rb_intern(f_name);
329 if (!rb_respond_to(module, *func))
332 DEBUG(
"load_function %s, result: %lu", f_name, *func);
358 ruby_init_loadpath();
369 ERROR(
"Ruby rb_define_module failed");
384 rb_define_module_function(module,
"radlog",
radlog_rb, 2);
387 rb_load_protect(rb_str_new2(inst->
filename), 0, &status);
389 ERROR(
"Error loading file %s status: %d", inst->
filename, status);
398 #define RLM_RUBY_LOAD(foo) if (load_function(#foo, &inst->func_##foo, inst->module)==-1) { \
418 return do_ruby(NULL, inst->func_instantiate, inst->
module,
"instantiate");
421 #define RLM_RUBY_FUNC(foo) static rlm_rcode_t CC_HINT(nonnull) mod_##foo(void *instance, REQUEST *request) \
423 return do_ruby(request, \
424 ((struct rlm_ruby_t *)instance)->func_##foo,((struct rlm_ruby_t *)instance)->module, \
464 .config = module_config,
5 methods index for preproxy section.
#define PW_TYPE_FILE_INPUT
File matching value must exist, and must be readable.
Only displayed when debugging is enabled.
Main server configuration.
static rlm_rcode_t mod_accounting(void *instance, REQUEST *request)
Write accounting data to Couchbase documents.
The module is OK, continue.
static rlm_rcode_t mod_post_auth(void *instance, REQUEST *request) CC_HINT(nonnull)
Metadata exported by the module.
int radlog(log_type_t lvl, char const *fmt,...) CC_HINT(format(printf
#define RLM_TYPE_THREAD_UNSAFE
Module is not threadsafe.
RLM_RUBY_STRUCT(instantiate)
static VALUE radlog_rb(UNUSED VALUE self, VALUE msg_type, VALUE rb_msg)
7 methods index for postauth section.
static rlm_rcode_t mod_authorize(void *instance, REQUEST *request)
Handle authorization requests using Couchbase document data.
int8_t tag
Tag value used to group valuepairs.
void size_t fr_pair_value_snprint(char *out, size_t outlen, VALUE_PAIR const *vp, char quote)
Print the value of an attribute to a string.
#define CONF_PARSER_TERMINATOR
static int mod_detach(UNUSED void *instance)
VALUE_PAIR * fr_cursor_init(vp_cursor_t *cursor, VALUE_PAIR *const *node)
Setup a cursor to iterate over attribute pairs.
PUBLIC int snprintf(char *string, size_t length, char *format, va_alist)
The module considers the request invalid.
char const * name
Name of the daemon, usually 'radiusd'.
static rlm_rcode_t mod_authenticate(void *instance, REQUEST *request) CC_HINT(nonnull)
#define RLM_RUBY_LOAD(foo)
Defines a CONF_PAIR to C data type mapping.
Abstraction to allow iterating over different configurations of VALUE_PAIRs.
fr_dict_attr_flags_t flags
Flags.
Reject the request (user is locked out).
static const CONF_PARSER module_config[]
4 methods index for checksimul section.
Immediately reject the request.
3 methods index for accounting section.
Stores an attribute, a value and various bits of other data.
static rlm_rcode_t mod_checksimul(void *instance, REQUEST *request)
Check if a given user is already logged in.
0 methods index for authenticate section.
static int mod_instantiate(UNUSED CONF_SECTION *conf, void *instance)
enum rlm_rcodes rlm_rcode_t
Return codes indicating the result of the module call.
Module succeeded without doing anything.
char name[1]
Attribute name.
uint64_t magic
Used to validate module struct.
Module failed, don't reply.
static int load_function(char const *f_name, unsigned long *func, VALUE module)
static void add_vp_tuple(TALLOC_CTX *ctx, REQUEST *request, VALUE_PAIR **vpp, VALUE rb_value, char const *function_name)
#define FR_CONF_OFFSET(_n, _t, _s, _f)
VALUE_PAIR * fr_cursor_next(vp_cursor_t *cursor)
Advanced the cursor to the next VALUE_PAIR.
unsigned int has_tag
Tagged attribute.
static struct varlookup constants[]
6 methods index for postproxy section.
2 methods index for preacct section.
#define PW_TYPE_REQUIRED
Error out if no matching CONF_PAIR is found, and no dflt value is set.
8 methods index for recvcoa section.
size_t strlcpy(char *dst, char const *src, size_t siz)
fr_dict_attr_t const * da
Dictionary attribute defines the attribute.
9 methods index for sendcoa section.
How many valid return codes there are.
String of printable characters.
1 methods index for authorize section.
The module handled the request, so stop.
VALUE_PAIR * fr_pair_make(TALLOC_CTX *ctx, VALUE_PAIR **vps, char const *attribute, char const *value, FR_TOKEN op)
Create a VALUE_PAIR from ASCII strings.
#define RLM_RUBY_FUNC(foo)
static rlm_rcode_t CC_HINT(nonnull(4))
struct rlm_ruby_t rlm_ruby_t