All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Typedefs | Enumerations | Functions | Variables
rlm_expr.c File Reference

Register many xlat expansions including the expr expansion. More...

#include <freeradius-devel/radiusd.h>
#include <freeradius-devel/md5.h>
#include <freeradius-devel/sha1.h>
#include <freeradius-devel/base64.h>
#include <freeradius-devel/modules.h>
#include <freeradius-devel/rad_assert.h>
#include <ctype.h>
#include "rlm_expr.h"
+ Include dependency graph for rlm_expr.c:

Go to the source code of this file.

Data Structures

struct  expr_map_t
 
struct  rlm_expr_t
 

Typedefs

typedef struct expr_map_t expr_map_t
 
typedef enum expr_token_t expr_token_t
 
typedef
USES_APPLE_DEPRECATED_API
struct rlm_expr_t 
rlm_expr_t
 

Enumerations

enum  expr_token_t {
  TOKEN_NONE = 0,
  TOKEN_INTEGER,
  TOKEN_AND,
  TOKEN_OR,
  TOKEN_LSHIFT,
  TOKEN_RSHIFT,
  TOKEN_ADD,
  TOKEN_SUBTRACT,
  TOKEN_DIVIDE,
  TOKEN_REMAINDER,
  TOKEN_MULTIPLY,
  TOKEN_POWER,
  TOKEN_LAST
}
 

Functions

static ssize_t base64_to_hex_xlat (char **out, size_t outlen, UNUSED void const *mod_inst, UNUSED void const *xlat_inst, REQUEST *request, char const *fmt)
 Convert base64 to hex. More...
 
static ssize_t base64_xlat (char **out, size_t outlen, UNUSED void const *mod_inst, UNUSED void const *xlat_inst, REQUEST *request, char const *fmt)
 Encode string or attribute as base64. More...
 
static bool calc_result (REQUEST *request, int64_t lhs, expr_token_t op, int64_t rhs, int64_t *answer)
 
static ssize_t escape_xlat (char **out, size_t outlen, void const *mod_inst, UNUSED void const *xlat_inst, UNUSED REQUEST *request, char const *fmt)
 Equivalent to the old safe_characters functionality in rlm_sql but with utf8 support. More...
 
static ssize_t explode_xlat (char **out, size_t outlen, UNUSED void const *mod_inst, UNUSED void const *xlat_inst, REQUEST *request, char const *fmt)
 Split an attribute into multiple new attributes based on a delimiter. More...
 
static ssize_t expr_xlat (char **out, size_t outlen, UNUSED void const *mod_inst, UNUSED void const *xlat_inst, REQUEST *request, char const *fmt)
 
static int64_t fr_pow (int64_t base, int64_t exp)
 Calculate powers. More...
 
static bool get_expression (REQUEST *request, char const **string, int64_t *answer, expr_token_t prev)
 
static bool get_number (REQUEST *request, char const **string, int64_t *answer)
 
static bool get_operator (REQUEST *request, char const **string, expr_token_t *op)
 
static ssize_t hmac_md5_xlat (char **out, size_t outlen, UNUSED void const *mod_inst, UNUSED void const *xlat_inst, REQUEST *request, char const *fmt)
 Calculate any digest supported by OpenSSL EVP_MD. More...
 
static ssize_t hmac_sha1_xlat (char **out, size_t outlen, UNUSED void const *mod_inst, UNUSED void const *xlat_inst, REQUEST *request, char const *fmt)
 Generate the HMAC-SHA1 of a string or attribute. More...
 
static ssize_t lc_xlat (char **out, size_t outlen, UNUSED void const *mod_inst, UNUSED void const *xlat_inst, UNUSED REQUEST *request, char const *fmt)
 Convert a string to lowercase. More...
 
static ssize_t lpad_xlat (char **out, size_t outlen, UNUSED void const *mod_inst, UNUSED void const *xlat_inst, REQUEST *request, char const *fmt)
 left pad a string More...
 
static ssize_t md5_xlat (char **out, size_t outlen, UNUSED void const *mod_inst, UNUSED void const *xlat_inst, REQUEST *request, char const *fmt)
 Calculate the MD5 hash of a string or attribute. More...
 
static int mod_bootstrap (CONF_SECTION *conf, void *instance)
 
static ssize_t next_time_xlat (char **out, size_t outlen, UNUSED void const *mod_inst, UNUSED void const *xlat_inst, REQUEST *request, char const *fmt)
 Calculate number of seconds until the next n hour(s), day(s), week(s), year(s). More...
 
static ssize_t pairs_xlat (char **out, size_t outlen, UNUSED void const *mod_inst, UNUSED void const *xlat_inst, REQUEST *request, char const *fmt)
 Encode attributes as a series of string attribute/value pairs. More...
 
static bool parse_pad (REQUEST *request, char const *fmt, vp_tmpl_t **pvpt, size_t *plength, char *fill)
 
static ssize_t rand_xlat (char **out, size_t outlen, UNUSED void const *mod_inst, UNUSED void const *xlat_inst, UNUSED REQUEST *request, char const *fmt)
 Generate a random integer value. More...
 
static ssize_t randstr_xlat (char **out, size_t outlen, UNUSED void const *mod_inst, UNUSED void const *xlat_inst, UNUSED REQUEST *request, char const *fmt)
 Generate a string of random chars. More...
 
static ssize_t rpad_xlat (char **out, size_t outlen, UNUSED void const *mod_inst, UNUSED void const *xlat_inst, REQUEST *request, char const *fmt)
 right pad a string More...
 
static ssize_t sha1_xlat (char **out, size_t outlen, UNUSED void const *mod_inst, UNUSED void const *xlat_inst, REQUEST *request, char const *fmt)
 Calculate the SHA1 hash of a string or attribute. More...
 
static ssize_t uc_xlat (char **out, size_t outlen, UNUSED void const *mod_inst, UNUSED void const *xlat_inst, UNUSED REQUEST *request, char const *fmt)
 Convert a string to uppercase. More...
 
static ssize_t unescape_xlat (char **out, size_t outlen, UNUSED void const *mod_inst, UNUSED void const *xlat_inst, UNUSED REQUEST *request, char const *fmt)
 Equivalent to the old safe_characters functionality in rlm_sql. More...
 
static ssize_t urlquote_xlat (char **out, size_t outlen, UNUSED void const *mod_inst, UNUSED void const *xlat_inst, UNUSED REQUEST *request, char const *fmt)
 URLencode special characters. More...
 
static ssize_t urlunquote_xlat (char **out, size_t outlen, UNUSED void const *mod_inst, UNUSED void const *xlat_inst, REQUEST *request, char const *fmt)
 URLdecode special characters. More...
 

Variables

static char const hextab [] = "0123456789abcdef"
 
static expr_map_t map []
 
static const CONF_PARSER module_config []
 
static int precedence [TOKEN_LAST+1]
 
static char randstr_otp [] = "469ACGHJKLMNPQRUVWXYabdfhijkprstuvwxyz"
 
static char randstr_punc [] = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
 
static char randstr_salt [] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmopqrstuvwxyz/."
 
module_t rlm_expr
 

Detailed Description

Register many xlat expansions including the expr expansion.

Id:
b0f34c57fb69956828d32446274517a876d2e4db

Definition in file rlm_expr.c.


Data Structure Documentation

struct expr_map_t

Definition at line 164 of file rlm_expr.c.

Data Fields
char op
expr_token_t token
struct rlm_expr_t

Definition at line 46 of file rlm_expr.c.

Data Fields
char const * allowed_chars
char const * xlat_name

Typedef Documentation

typedef struct expr_map_t expr_map_t
typedef enum expr_token_t expr_token_t

Enumeration Type Documentation

Enumerator
TOKEN_NONE 
TOKEN_INTEGER 
TOKEN_AND 
TOKEN_OR 
TOKEN_LSHIFT 
TOKEN_RSHIFT 
TOKEN_ADD 
TOKEN_SUBTRACT 
TOKEN_DIVIDE 
TOKEN_REMAINDER 
TOKEN_MULTIPLY 
TOKEN_POWER 
TOKEN_LAST 

Definition at line 136 of file rlm_expr.c.

Function Documentation

static ssize_t base64_to_hex_xlat ( char **  out,
size_t  outlen,
UNUSED void const *  mod_inst,
UNUSED void const *  xlat_inst,
REQUEST request,
char const *  fmt 
)
static

Convert base64 to hex.

Example: "%{base64tohex:Zm9v}" == "666f6f"

Definition at line 1226 of file rlm_expr.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ssize_t base64_xlat ( char **  out,
size_t  outlen,
UNUSED void const *  mod_inst,
UNUSED void const *  xlat_inst,
REQUEST request,
char const *  fmt 
)
static

Encode string or attribute as base64.

Example: "%{base64:foo}" == "Zm9v"

Definition at line 1198 of file rlm_expr.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool calc_result ( REQUEST request,
int64_t  lhs,
expr_token_t  op,
int64_t  rhs,
int64_t *  answer 
)
static

Definition at line 315 of file rlm_expr.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ssize_t escape_xlat ( char **  out,
size_t  outlen,
void const *  mod_inst,
UNUSED void const *  xlat_inst,
UNUSED REQUEST request,
char const *  fmt 
)
static

Equivalent to the old safe_characters functionality in rlm_sql but with utf8 support.

Example: "%{escape:<img>foo.jpg</img>}" == "=60img=62foo.jpg=60/img=62" 

Definition at line 775 of file rlm_expr.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ssize_t explode_xlat ( char **  out,
size_t  outlen,
UNUSED void const *  mod_inst,
UNUSED void const *  xlat_inst,
REQUEST request,
char const *  fmt 
)
static

Split an attribute into multiple new attributes based on a delimiter.

Todo:
should support multibyte delimiter for string types.

Example: "%{explode:&ref <delim>}"

Definition at line 1256 of file rlm_expr.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ssize_t expr_xlat ( char **  out,
size_t  outlen,
UNUSED void const *  mod_inst,
UNUSED void const *  xlat_inst,
REQUEST request,
char const *  fmt 
)
static

Definition at line 489 of file rlm_expr.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int64_t fr_pow ( int64_t  base,
int64_t  exp 
)
static

Calculate powers.

Author
Orson Peters
Note
Borrowed from the gist here: https://gist.github.com/nightcracker/3551590.
Parameters
basea 32bit signed integer.
expamount to raise base by.
Returns
base ^ pow, or 0 on underflow/overflow.

Definition at line 79 of file rlm_expr.c.

+ Here is the caller graph for this function:

static bool get_expression ( REQUEST request,
char const **  string,
int64_t *  answer,
expr_token_t  prev 
)
static

Definition at line 426 of file rlm_expr.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool get_number ( REQUEST request,
char const **  string,
int64_t *  answer 
)
static

Definition at line 184 of file rlm_expr.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool get_operator ( REQUEST request,
char const **  string,
expr_token_t op 
)
static

Definition at line 393 of file rlm_expr.c.

+ Here is the caller graph for this function:

static ssize_t hmac_md5_xlat ( char **  out,
size_t  outlen,
UNUSED void const *  mod_inst,
UNUSED void const *  xlat_inst,
REQUEST request,
char const *  fmt 
)
static

Calculate any digest supported by OpenSSL EVP_MD.

Example: "%{sha256:foo}" == "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33" Generate the HMAC-MD5 of a string or attribute

Example: "%{hmacmd5:foo bar}" == "Zm9v"

Definition at line 1046 of file rlm_expr.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ssize_t hmac_sha1_xlat ( char **  out,
size_t  outlen,
UNUSED void const *  mod_inst,
UNUSED void const *  xlat_inst,
REQUEST request,
char const *  fmt 
)
static

Generate the HMAC-SHA1 of a string or attribute.

Example: "%{hmacsha1:foo bar}" == "Zm9v"

Definition at line 1093 of file rlm_expr.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ssize_t lc_xlat ( char **  out,
size_t  outlen,
UNUSED void const *  mod_inst,
UNUSED void const *  xlat_inst,
UNUSED REQUEST request,
char const *  fmt 
)
static

Convert a string to lowercase.

Example: "%{tolower:Bar}" == "bar"

Probably only works for ASCII

Definition at line 883 of file rlm_expr.c.

+ Here is the caller graph for this function:

static ssize_t lpad_xlat ( char **  out,
size_t  outlen,
UNUSED void const *  mod_inst,
UNUSED void const *  xlat_inst,
REQUEST request,
char const *  fmt 
)
static

left pad a string

%{lpad:&Attribute-Name length 'x'}

Definition at line 1542 of file rlm_expr.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ssize_t md5_xlat ( char **  out,
size_t  outlen,
UNUSED void const *  mod_inst,
UNUSED void const *  xlat_inst,
REQUEST request,
char const *  fmt 
)
static

Calculate the MD5 hash of a string or attribute.

Example: "%{md5:foo}" == "acbd18db4cc2f85cedef654fccc4a4d8"

Definition at line 933 of file rlm_expr.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int mod_bootstrap ( CONF_SECTION conf,
void *  instance 
)
static

Definition at line 1627 of file rlm_expr.c.

+ Here is the call graph for this function:

static ssize_t next_time_xlat ( char **  out,
size_t  outlen,
UNUSED void const *  mod_inst,
UNUSED void const *  xlat_inst,
REQUEST request,
char const *  fmt 
)
static

Calculate number of seconds until the next n hour(s), day(s), week(s), year(s).

For example, if it were 16:18 %{nexttime:1h} would expand to 2520.

The envisaged usage for this function is to limit sessions so that they don't cross billing periods. The output of the xlat should be combined with %{rand:} to create some jitter, unless the desired effect is every subscriber on the network re-authenticating at the same time.

Definition at line 1393 of file rlm_expr.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ssize_t pairs_xlat ( char **  out,
size_t  outlen,
UNUSED void const *  mod_inst,
UNUSED void const *  xlat_inst,
REQUEST request,
char const *  fmt 
)
static

Encode attributes as a series of string attribute/value pairs.

This is intended to serialize one or more attributes as a comma delimited string.

Example: "%{pairs:request:}" == "User-Name = 'foo', User-Password = 'bar'"

Definition at line 1143 of file rlm_expr.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool parse_pad ( REQUEST request,
char const *  fmt,
vp_tmpl_t **  pvpt,
size_t *  plength,
char *  fill 
)
static

Definition at line 1464 of file rlm_expr.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ssize_t rand_xlat ( char **  out,
size_t  outlen,
UNUSED void const *  mod_inst,
UNUSED void const *  xlat_inst,
UNUSED REQUEST request,
char const *  fmt 
)
static

Generate a random integer value.

Definition at line 514 of file rlm_expr.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ssize_t randstr_xlat ( char **  out,
size_t  outlen,
UNUSED void const *  mod_inst,
UNUSED void const *  xlat_inst,
UNUSED REQUEST request,
char const *  fmt 
)
static

Generate a string of random chars.

Build strings of random chars, useful for generating tokens and passcodes Format similar to String::Random.

Definition at line 540 of file rlm_expr.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ssize_t rpad_xlat ( char **  out,
size_t  outlen,
UNUSED void const *  mod_inst,
UNUSED void const *  xlat_inst,
REQUEST request,
char const *  fmt 
)
static

right pad a string

%{rpad:&Attribute-Name length 'x'}

Definition at line 1582 of file rlm_expr.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ssize_t sha1_xlat ( char **  out,
size_t  outlen,
UNUSED void const *  mod_inst,
UNUSED void const *  xlat_inst,
REQUEST request,
char const *  fmt 
)
static

Calculate the SHA1 hash of a string or attribute.

Example: "%{sha1:foo}" == "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33"

Definition at line 965 of file rlm_expr.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ssize_t uc_xlat ( char **  out,
size_t  outlen,
UNUSED void const *  mod_inst,
UNUSED void const *  xlat_inst,
UNUSED REQUEST request,
char const *  fmt 
)
static

Convert a string to uppercase.

Example: "%{toupper:Foo}" == "FOO"

Probably only works for ASCII

Definition at line 909 of file rlm_expr.c.

+ Here is the caller graph for this function:

static ssize_t unescape_xlat ( char **  out,
size_t  outlen,
UNUSED void const *  mod_inst,
UNUSED void const *  xlat_inst,
UNUSED REQUEST request,
char const *  fmt 
)
static

Equivalent to the old safe_characters functionality in rlm_sql.

Example: "%{unescape:=60img=62foo.jpg=60/img=62}" == "<img>foo.jpg</img>" 

Definition at line 842 of file rlm_expr.c.

+ Here is the caller graph for this function:

static ssize_t urlquote_xlat ( char **  out,
size_t  outlen,
UNUSED void const *  mod_inst,
UNUSED void const *  xlat_inst,
UNUSED REQUEST request,
char const *  fmt 
)
static

URLencode special characters.

Example: "%{urlquote:http://example.org/}" == "http%3A%47%47example.org%47"

Definition at line 688 of file rlm_expr.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ssize_t urlunquote_xlat ( char **  out,
size_t  outlen,
UNUSED void const *  mod_inst,
UNUSED void const *  xlat_inst,
REQUEST request,
char const *  fmt 
)
static

URLdecode special characters.

Example: "%{urlunquote:http%%3A%%47%%47example.org%%47}" == "http://example.org/"

Remember to escape % with %% in strings, else xlat will try to parse it.

Definition at line 737 of file rlm_expr.c.

+ Here is the caller graph for this function:

Variable Documentation

char const hextab[] = "0123456789abcdef"
static

Definition at line 68 of file rlm_expr.c.

expr_map_t map[]
static
Initial value:

Definition at line 169 of file rlm_expr.c.

const CONF_PARSER module_config[]
static
Initial value:
= {
{ FR_CONF_OFFSET("safe_characters", PW_TYPE_STRING, rlm_expr_t, allowed_chars), .dflt = "@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_: /" },
}
#define CONF_PARSER_TERMINATOR
Definition: conffile.h:289
#define FR_CONF_OFFSET(_n, _t, _s, _f)
Definition: conffile.h:168
String of printable characters.
Definition: radius.h:33

Definition at line 51 of file rlm_expr.c.

int precedence[TOKEN_LAST+1]
static
Initial value:
= {
0, 0, 1, 1,
2, 2, 3, 3,
4, 4, 4, 5,
0
}

Definition at line 157 of file rlm_expr.c.

char randstr_otp[] = "469ACGHJKLMNPQRUVWXYabdfhijkprstuvwxyz"
static

Definition at line 66 of file rlm_expr.c.

char randstr_punc[] = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
static

Definition at line 59 of file rlm_expr.c.

char randstr_salt[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmopqrstuvwxyz/."
static

Definition at line 60 of file rlm_expr.c.

module_t rlm_expr
Initial value:
= {
.magic = RLM_MODULE_INIT,
.name = "expr",
.inst_size = sizeof(rlm_expr_t),
.config = module_config,
.bootstrap = mod_bootstrap,
}
#define RLM_MODULE_INIT
Definition: modules.h:86
USES_APPLE_DEPRECATED_API struct rlm_expr_t rlm_expr_t
static int mod_bootstrap(CONF_SECTION *conf, void *instance)
Definition: rlm_expr.c:1627
static const CONF_PARSER module_config[]
Definition: rlm_expr.c:51

Definition at line 1682 of file rlm_expr.c.