The FreeRADIUS server $Id: f3670dba8951ca10eb4948feb3dc3db9423a334f $
Loading...
Searching...
No Matches
Macros | Typedefs | Enumerations | Functions | Variables
misc.h File Reference

Various miscellaneous utility functions. More...

#include <freeradius-devel/build.h>
#include <freeradius-devel/missing.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/print.h>
#include <freeradius-devel/util/strerror.h>
#include <freeradius-devel/util/talloc.h>
#include <freeradius-devel/util/time.h>
#include <signal.h>
+ Include dependency graph for misc.h:

Go to the source code of this file.

Macros

#define fr_zero_whitespace(_p)   while (isspace((uint8_t) *_p)) *(_p++) = '\0'
 Zero out any whitespace with nul bytes.
 
#define VERIFY_ALL_TALLOC
 

Typedefs

typedef fr_cmp_ret_t(* fr_cmp_t) (void const *a, void const *b)
 
typedef void(* fr_free_t) (void *)
 
typedef void(* fr_suid_t) (void)
 

Enumerations

enum  fr_cmp_ret_t : int8_t {
  CMP_ERR = INT8_MIN ,
  CMP_LT = -1 ,
  CMP_EQ = 0 ,
  CMP_GT = 1
}
 Result of an ordering comparison. More...
 

Functions

int fr_blocking (int fd)
 
int fr_cloexec (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.
 
int fr_nonblock (int fd)
 
fr_cmp_ret_t fr_pointer_cmp (void const *a, void const *b)
 Compares two pointers.
 
int fr_quick_sort (void const *to_sort[], int min_idx, int max_idx, 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.
 
void fr_suid_noop (void)
 
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 bool is_integer (char const *value)
 Check whether the string is all numbers.
 
static bool is_printable (void const *value, size_t len)
 Check whether the string is made up of printable UTF8 chars.
 
static bool is_whitespace (char const *value)
 Check whether the string is all whitespace.
 
static bool is_zero (char const *value)
 Check whether the string is all zeros.
 
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)
 

Variables

fr_suid_t fr_suid_down
 
fr_suid_t fr_suid_up
 

Detailed Description

Various miscellaneous utility functions.

Definition in file misc.h.

Macro Definition Documentation

◆ fr_zero_whitespace

#define fr_zero_whitespace (   _p)    while (isspace((uint8_t) *_p)) *(_p++) = '\0'

Zero out any whitespace with nul bytes.

Parameters
[in,out]_pstring to process

Definition at line 78 of file misc.h.

◆ VERIFY_ALL_TALLOC

#define VERIFY_ALL_TALLOC

Definition at line 71 of file misc.h.

Typedef Documentation

◆ fr_cmp_t

typedef fr_cmp_ret_t(* fr_cmp_t) (void const *a, void const *b)

Definition at line 57 of file misc.h.

◆ fr_free_t

typedef void(* fr_free_t) (void *)

Definition at line 58 of file misc.h.

◆ fr_suid_t

typedef void(* fr_suid_t) (void)

Definition at line 181 of file misc.h.

Enumeration Type Documentation

◆ fr_cmp_ret_t

enum fr_cmp_ret_t : int8_t

Result of an ordering comparison.

CMP_ERR means the comparison itself failed (corrupt or invalid operand), not that the operands were unequal. A comparator returning CMP_ERR also pushes a fr_strerror describing the operand problem.

CMP_ERR is negative, so sign-test idioms (ret < 0) misread an error as "less than". Any consumer which can receive CMP_ERR must check for the value explicitly before interpreting the sign.

Enumerator
CMP_ERR 

comparison failed

CMP_LT 

a < b

CMP_EQ 

a == b

CMP_GT 

a > b

Definition at line 50 of file misc.h.

Function Documentation

◆ fr_blocking()

int fr_blocking ( int  fd)

◆ fr_cloexec()

int fr_cloexec ( int  fd)

◆ 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 516 of file misc.c.

+ Here is the caller graph for this function:

◆ fr_nonblock()

int fr_nonblock ( int  fd)

◆ fr_pointer_cmp()

fr_cmp_ret_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 449 of file misc.c.

+ Here is the caller graph for this function:

◆ fr_quick_sort()

int 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.
Returns
  • 0 on success.
  • -1 on comparator error, retrieve the error with fr_strerror. The array is a permutation of its input but its order is undefined.

Definition at line 495 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 47 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 401 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 191 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 160 of file misc.c.

◆ fr_suid_noop()

void fr_suid_noop ( void  )

Definition at line 529 of file misc.c.

+ Here is the caller graph for this function:

◆ fr_tolower()

char * fr_tolower ( char *  str)

Definition at line 225 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 213 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 76 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 347 of file misc.c.

+ Here is the caller graph for this function:

◆ is_integer()

static bool is_integer ( char const *  value)
inlinestatic

Check whether the string is all numbers.

Returns
  • true if the entirety of the string is number chars.
  • false if string contains non-numeric chars or is empty.

Definition at line 128 of file misc.h.

+ Here is the caller graph for this function:

◆ is_printable()

static bool is_printable ( void const *  value,
size_t  len 
)
inlinestatic

Check whether the string is made up of printable UTF8 chars.

Parameters
valueto check.
lenof value.
Returns
  • true if the string is printable.
  • false if the string contains non printable chars

Definition at line 107 of file misc.h.

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

◆ is_whitespace()

static bool is_whitespace ( char const *  value)
inlinestatic

Check whether the string is all whitespace.

Returns
  • true if the entirety of the string is whitespace.
  • false if the string contains non whitespace.

Definition at line 86 of file misc.h.

+ Here is the caller graph for this function:

◆ is_zero()

static bool is_zero ( char const *  value)
inlinestatic

Check whether the string is all zeros.

Returns
  • true if the entirety of the string is all zeros.
  • false if string contains non-zero chars or is empty.

Definition at line 146 of file misc.h.

◆ rad_lockfd()

int rad_lockfd ( int  fd,
int  lock_len 
)

Definition at line 119 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 129 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 141 of file misc.c.

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

Variable Documentation

◆ fr_suid_down

fr_suid_t fr_suid_down
extern

Definition at line 534 of file misc.c.

◆ fr_suid_up

fr_suid_t fr_suid_up
extern

Definition at line 533 of file misc.c.