The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Functions | Variables
util.h File Reference

Various utility functions. More...

#include <pwd.h>
#include <grp.h>
#include <freeradius-devel/util/talloc.h>
+ Include dependency graph for util.h:

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...
 
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)
 
ssize_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...
 
ssize_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))
 

Detailed Description

Various utility functions.

Id
7c0485d583037ba0f103059322d4038ee75e96fd

Definition in file util.h.

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 398 of file util.c.

+ Here is the call 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 599 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 292 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 167 of file util.c.

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

◆ rad_filename_escape()

ssize_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 216 of file util.c.

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

◆ rad_filename_make_safe()

ssize_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 96 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 336 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 549 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 951 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 929 of file util.c.

+ Here is the call graph for this function:

◆ rad_suid_down()

void rad_suid_down ( void  )

Definition at line 900 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 905 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 917 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 892 of file util.c.

◆ rad_suid_up()

void rad_suid_up ( void  )

Definition at line 896 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 36 of file util.h.