The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
Macros | Functions
misc.c File Reference

Various miscellaneous utility functions. More...

#include <freeradius-devel/util/dbuff.h>
#include <freeradius-devel/util/sbuff.h>
#include <freeradius-devel/util/syserror.h>
#include <string.h>
#include <fcntl.h>
#include <grp.h>
#include <pwd.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/uio.h>
+ Include dependency graph for misc.c:

Go to the source code of this file.

Macros

#define FR_PUT_LE16(a, val)
 
#define SWAP(_a, _b)
 

Functions

int fr_blocking (UNUSED int fd)
 
int fr_digest_cmp (uint8_t const *a, uint8_t const *b, size_t length)
 Do a comparison of two authentication digests by comparing the FULL data.
 
char const * fr_filename (char const *path)
 Get the filename from a path.
 
char const * fr_filename_common_trim (char const *path, char const *common)
 Get the filename from a path.
 
int fr_nonblock (UNUSED int fd)
 
int8_t fr_pointer_cmp (void const *a, void const *b)
 Compares two pointers.
 
void fr_quick_sort (void const *to_sort[], int start, int end, fr_cmp_t cmp)
 Quick sort an array of pointers using a comparator.
 
int fr_set_signal (int sig, sig_t func)
 Sets a signal handler using sigaction if available, else signal.
 
size_t fr_snprint_uint128 (char *out, size_t outlen, uint128_t const num)
 Write 128bit unsigned integer to buffer.
 
int fr_strtoll (int64_t *out, char **end, char const *value)
 Consume the integer (or hex) portion of a value string.
 
int fr_strtoull (uint64_t *out, char **end, char const *value)
 Consume the integer (or hex) portion of a value string.
 
char * fr_tolower (char *str)
 
char * fr_trim (char const *str, size_t size)
 Trim whitespace from the end of a string.
 
int fr_unset_signal (int sig)
 Uninstall a signal for a specific handler.
 
ssize_t fr_utf8_to_ucs2 (uint8_t *out, size_t outlen, char const *in, size_t inlen)
 Convert UTF8 string to UCS2 encoding.
 
static int rad_lock (int fd, int lock_len, int cmd, int type)
 
int rad_lockfd (int fd, int lock_len)
 
int rad_lockfd_nonblock (int fd, int lock_len)
 
int rad_unlockfd (int fd, int lock_len)
 

Detailed Description

Various miscellaneous utility functions.

Definition in file misc.c.

Macro Definition Documentation

◆ FR_PUT_LE16

#define FR_PUT_LE16 (   a,
  val 
)
Value:
do {\
a[1] = ((uint16_t) (val)) >> 8;\
a[0] = ((uint16_t) (val)) & 0xff;\
} while (0)
unsigned short uint16_t

Definition at line 37 of file misc.c.

◆ SWAP

#define SWAP (   _a,
  _b 
)
Value:
do { \
void const *_tmp = to_sort[_a]; \
to_sort[_a] = to_sort[_b]; \
to_sort[_b] = _tmp; \
} while (0)

Function Documentation

◆ fr_blocking()

int fr_blocking ( UNUSED int  fd)

Definition at line 299 of file misc.c.

+ Here is the caller graph for this function:

◆ fr_digest_cmp()

int fr_digest_cmp ( uint8_t const *  a,
uint8_t const *  b,
size_t  length 
)

Do a comparison of two authentication digests by comparing the FULL data.

Otherwise, the server can be subject to timing attacks.

http://www.cs.rice.edu/~dwallach/pub/crosby-timing2009.pdf

Definition at line 473 of file misc.c.

+ Here is the caller graph for this function:

◆ fr_filename()

char const * fr_filename ( char const *  path)

Get the filename from a path.

Parameters
pathto get filename from.
Returns
  • pointer to the filename in the path.
  • pointer to the path if no '/' is found.

Definition at line 490 of file misc.c.

◆ fr_filename_common_trim()

char const * fr_filename_common_trim ( char const *  path,
char const *  common 
)

Get the filename from a path.

Parameters
pathto get filename from.
Returns
  • pointer to the filename in the path.
  • pointer to the path if no '/' is found.

Definition at line 506 of file misc.c.

◆ fr_nonblock()

int fr_nonblock ( UNUSED int  fd)

Definition at line 294 of file misc.c.

+ Here is the caller graph for this function:

◆ fr_pointer_cmp()

int8_t fr_pointer_cmp ( void const *  a,
void const *  b 
)

Compares two pointers.

Parameters
afirst pointer to compare.
bsecond pointer to compare.
Returns
  • -1 if a < b.
  • +1 if b > a.
  • 0 if both equal.

Definition at line 418 of file misc.c.

+ Here is the caller graph for this function:

◆ fr_quick_sort()

void fr_quick_sort ( void const *  to_sort[],
int  start,
int  end,
fr_cmp_t  cmp 
)

Quick sort an array of pointers using a comparator.

Parameters
to_sortarray of pointers to sort.
startthe lowest index (usually 0).
endthe length of the array.
cmpthe comparison function to use to sort the array elements.

Definition at line 430 of file misc.c.

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

◆ fr_set_signal()

int fr_set_signal ( int  sig,
sig_t  func 
)

Sets a signal handler using sigaction if available, else signal.

Parameters
sigto set handler for.
funchandler to set.

Definition at line 48 of file misc.c.

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

◆ fr_snprint_uint128()

size_t fr_snprint_uint128 ( char *  out,
size_t  outlen,
uint128_t const  num 
)

Write 128bit unsigned integer to buffer.

Author
Alexey Frunze
Parameters
outwhere to write result to.
outlensize of out.
num128 bit integer.

Definition at line 370 of file misc.c.

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

◆ fr_strtoll()

int fr_strtoll ( int64_t *  out,
char **  end,
char const *  value 
)

Consume the integer (or hex) portion of a value string.

Allows integer or hex representations of integers (but not octal, as octal is deemed to be confusing).

Note
Check for overflow with errno == ERANGE.
Parameters
[out]outResult of parsing string as signed 64bit integer.
[out]endpointer to the first non numeric char.
[in]valuestring to parse.
Returns
integer value.

Definition at line 192 of file misc.c.

◆ fr_strtoull()

int fr_strtoull ( uint64_t *  out,
char **  end,
char const *  value 
)

Consume the integer (or hex) portion of a value string.

Allows integer or hex representations of integers (but not octal, as octal is deemed to be confusing).

Parameters
[out]outResult of parsing string as unsigned 64bit integer.
[out]endpointer to the first non numeric char.
[in]valuestring to parse.
Returns
integer value.

Definition at line 161 of file misc.c.

◆ fr_tolower()

char * fr_tolower ( char *  str)

Definition at line 226 of file misc.c.

+ Here is the caller graph for this function:

◆ fr_trim()

char * fr_trim ( char const *  str,
size_t  size 
)

Trim whitespace from the end of a string.

Definition at line 214 of file misc.c.

◆ fr_unset_signal()

int fr_unset_signal ( int  sig)

Uninstall a signal for a specific handler.

man sigaction says these are fine to call from a signal handler.

Parameters
sigSIGNAL

Definition at line 77 of file misc.c.

+ Here is the caller graph for this function:

◆ fr_utf8_to_ucs2()

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

Convert UTF8 string to UCS2 encoding.

Note
Borrowed from src/crypto/ms_funcs.c of wpa_supplicant project (http://hostap.epitest.fi/wpa_supplicant/)
Parameters
[out]outWhere to write the ucs2 string.
[in]outlenSize of output buffer.
[in]inUTF8 string to convert.
[in]inlenlength of UTF8 string.
Returns
the size of the UCS2 string written to the output buffer (in bytes).

Definition at line 316 of file misc.c.

+ Here is the caller graph for this function:

◆ rad_lock()

static int rad_lock ( int  fd,
int  lock_len,
int  cmd,
int  type 
)
static

Definition at line 104 of file misc.c.

+ Here is the caller graph for this function:

◆ rad_lockfd()

int rad_lockfd ( int  fd,
int  lock_len 
)

Definition at line 120 of file misc.c.

+ Here is the call graph for this function:

◆ rad_lockfd_nonblock()

int rad_lockfd_nonblock ( int  fd,
int  lock_len 
)

Definition at line 130 of file misc.c.

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

◆ rad_unlockfd()

int rad_unlockfd ( int  fd,
int  lock_len 
)

Definition at line 142 of file misc.c.

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