The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Functions | Variables
util.c File Reference
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/server/stats.h>
#include <freeradius-devel/server/util.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/base16.h>
#include <freeradius-devel/util/misc.h>
#include <freeradius-devel/util/perm.h>
#include <ctype.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/stat.h>
+ Include dependency graph for util.c:

Go to the source code of this file.

Functions

char * rad_ajoin (TALLOC_CTX *ctx, char const **argv, int argc, char c)
 talloc a buffer to hold the concatenated value of all elements of argv More...
 
static int rad_copy_string (char *to, char const *from)
 
static int rad_copy_string_bare (char *to, char const *from)
 
static int rad_copy_variable (char *to, char const *from)
 
int rad_expand_xlat (request_t *request, char const *cmd, int max_argc, char const *argv[], bool can_fail, size_t argv_buflen, char *argv_buf)
 Split string into words and expand each one. More...
 
int rad_filename_box_escape (fr_value_box_t *vb, UNUSED void *uxtc)
 
int rad_filename_box_make_safe (fr_value_box_t *vb, UNUSED void *uxtc)
 
size_t rad_filename_escape (UNUSED request_t *request, char *out, size_t outlen, char const *in, UNUSED void *arg)
 Escapes the raw string such that it should be safe to use as part of a file path. More...
 
size_t rad_filename_make_safe (UNUSED request_t *request, char *out, size_t outlen, char const *in, UNUSED void *arg)
 Ensures that a filename cannot walk up the directory structure. More...
 
ssize_t rad_filename_unescape (char *out, size_t outlen, char const *in, size_t inlen)
 Converts data stored in a file name back to its original form. More...
 
uint32_t rad_pps (uint32_t *past, uint32_t *present, time_t *then, struct timeval *now)
 
int rad_segid (gid_t gid)
 Alter the effective user id. More...
 
int rad_seuid (uid_t uid)
 Alter the effective user id. More...
 
void rad_suid_down (void)
 
void rad_suid_down_permanent (void)
 
bool rad_suid_is_down_permanent (void)
 Return whether we've permanently dropped root privileges. More...
 
void rad_suid_set_down_uid (uid_t uid)
 
void rad_suid_up (void)
 

Variables

void(*)(int) reset_signal (int signo, void(*func)(int))
 
static bool suid_down_permanent = false
 Record whether we've permanently dropped privilledges. More...
 

Function Documentation

◆ rad_ajoin()

char* rad_ajoin ( TALLOC_CTX *  ctx,
char const **  argv,
int  argc,
char  c 
)

talloc a buffer to hold the concatenated value of all elements of argv

Parameters
ctxto allocate buffer in.
argvarray of substrings.
argclength of array.
cseparation character. Optional, may be '\0' for no separator.
Returns
the concatenation of the elements of argv, separated by c.

Definition at line 396 of file util.c.

+ Here is the call graph for this function:

◆ rad_copy_string()

static int rad_copy_string ( char *  to,
char const *  from 
)
static

Definition at line 434 of file util.c.

+ Here is the caller graph for this function:

◆ rad_copy_string_bare()

static int rad_copy_string_bare ( char *  to,
char const *  from 
)
static

Definition at line 462 of file util.c.

+ Here is the caller graph for this function:

◆ rad_copy_variable()

static int rad_copy_variable ( char *  to,
char const *  from 
)
static

Definition at line 488 of file util.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rad_expand_xlat()

int rad_expand_xlat ( request_t request,
char const *  cmd,
int  max_argc,
char const *  argv[],
bool  can_fail,
size_t  argv_buflen,
char *  argv_buf 
)

Split string into words and expand each one.

Parameters
requestCurrent request.
cmdstring to split.
max_argcthe maximum number of arguments to split into.
argvWhere to write the pointers into argv_buf.
can_failIf false, stop processing if any of the xlat expansions fail.
argv_buflensize of argv_buf.
argv_buftemporary buffer we used to mangle/expand cmd. Pointers to offsets of this buffer will be written to argv.
Returns
argc or -1 on failure.

Definition at line 597 of file util.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rad_filename_box_escape()

int rad_filename_box_escape ( fr_value_box_t vb,
UNUSED void *  uxtc 
)

Definition at line 290 of file util.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rad_filename_box_make_safe()

int rad_filename_box_make_safe ( fr_value_box_t vb,
UNUSED void *  uxtc 
)

Definition at line 165 of file util.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rad_filename_escape()

size_t rad_filename_escape ( UNUSED request_t request,
char *  out,
size_t  outlen,
char const *  in,
UNUSED void *  arg 
)

Escapes the raw string such that it should be safe to use as part of a file path.

This function is designed to produce a string that's still readable but portable across the majority of file systems.

For security reasons it cannot remove characters from the name, and must not allow collisions to occur between different strings.

With that in mind '-' has been chosen as the escape character, and will be double escaped '-' -> '–' to avoid collisions.

Escaping should be reversible if the original string needs to be extracted.

Note
function takes additional arguments so that it may be used as an xlat escape function but it's fine to call it directly.
OSX/Unix/NTFS/VFAT have a max filename size of 255 bytes.
Parameters
requestCurrent request (may be NULL).
outOutput buffer.
outlenSize of the output buffer.
instring to escape.
argContext arguments (unused, should be NULL).

Definition at line 214 of file util.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rad_filename_make_safe()

size_t rad_filename_make_safe ( UNUSED request_t request,
char *  out,
size_t  outlen,
char const *  in,
UNUSED void *  arg 
)

Ensures that a filename cannot walk up the directory structure.

Also sanitizes control chars.

Parameters
requestCurrent request (may be NULL).
outOutput buffer.
outlenSize of the output buffer.
instring to escape.
argContext arguments (unused, should be NULL).

Definition at line 94 of file util.c.

+ Here is the caller graph for this function:

◆ rad_filename_unescape()

ssize_t rad_filename_unescape ( char *  out,
size_t  outlen,
char const *  in,
size_t  inlen 
)

Converts data stored in a file name back to its original form.

Parameters
outWhere to write the unescaped string (may be the same as in).
outlenLength of the output buffer.
inInput filename.
inlenLength of input.
Returns
  • Number of bytes written to output buffer
  • offset where parse error occurred on failure.

Definition at line 334 of file util.c.

◆ rad_pps()

uint32_t rad_pps ( uint32_t past,
uint32_t present,
time_t *  then,
struct timeval *  now 
)

Definition at line 547 of file util.c.

◆ rad_segid()

int rad_segid ( gid_t  gid)

Alter the effective user id.

Parameters
gidto set
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 949 of file util.c.

+ Here is the call graph for this function:

◆ rad_seuid()

int rad_seuid ( uid_t  uid)

Alter the effective user id.

Parameters
uidto set
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 927 of file util.c.

+ Here is the call graph for this function:

◆ rad_suid_down()

void rad_suid_down ( void  )

Definition at line 898 of file util.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rad_suid_down_permanent()

void rad_suid_down_permanent ( void  )

Definition at line 903 of file util.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rad_suid_is_down_permanent()

bool rad_suid_is_down_permanent ( void  )

Return whether we've permanently dropped root privileges.

Returns
  • true if root privileges have been dropped.
  • false if root privileges have not been dropped.

Definition at line 915 of file util.c.

+ Here is the caller graph for this function:

◆ rad_suid_set_down_uid()

void rad_suid_set_down_uid ( uid_t  uid)

Definition at line 890 of file util.c.

◆ rad_suid_up()

void rad_suid_up ( void  )

Definition at line 894 of file util.c.

+ Here is the caller graph for this function:

Variable Documentation

◆ reset_signal

void(*)(int) reset_signal(int signo, void(*func)(int)) ( int  signo,
void(*)(int)  func 
)

Definition at line 53 of file util.c.

◆ suid_down_permanent

bool suid_down_permanent = false
static

Record whether we've permanently dropped privilledges.

Definition at line 39 of file util.c.