The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Functions
print.c File Reference

Functions to produce and parse the FreeRADIUS presentation format. More...

#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/base16.h>
#include <freeradius-devel/util/pair.h>
+ Include dependency graph for print.c:

Go to the source code of this file.

Functions

char * fr_asprint (TALLOC_CTX *ctx, char const *in, ssize_t inlen, char quote)
 Escape string that may contain binary data, and write it to a new buffer. More...
 
char * fr_asprintf (TALLOC_CTX *ctx, char const *fmt,...)
 Special version of asprintf which implements custom format specifiers. More...
 
ssize_t fr_fprintf (FILE *fp, char const *fmt,...)
 Special version of fprintf which implements custom format specifiers. More...
 
size_t fr_snprint (char *out, size_t outlen, char const *in, ssize_t inlen, char quote)
 Escape any non printable or non-UTF8 characters in the input string. More...
 
size_t fr_snprint_len (char const *in, ssize_t inlen, char quote)
 Find the length of the buffer required to fully escape a string with fr_prints. More...
 
size_t fr_utf8_char (uint8_t const *str, ssize_t inlen)
 Checks for utf-8, taken from http://www.w3.org/International/questions/qa-forms-utf-8. More...
 
fr_slen_t fr_utf8_str (uint8_t const *str, ssize_t inlen)
 Validate a complete UTF8 string. More...
 
char const * fr_utf8_strchr (int *out_chr_len, char const *str, ssize_t inlen, char const *chr)
 Return a pointer to the first UTF8 char in a string. More...
 
char * fr_vasprintf (TALLOC_CTX *ctx, char const *fmt, va_list ap)
 
static char * fr_vasprintf_internal (TALLOC_CTX *ctx, char const *fmt, va_list ap, bool suppress_secrets)
 Special version of vasprintf which implements custom format specifiers. More...
 
char * fr_vasprintf_secure (TALLOC_CTX *ctx, char const *fmt, va_list ap)
 

Detailed Description

Functions to produce and parse the FreeRADIUS presentation format.

Definition in file print.c.

Function Documentation

◆ fr_asprint()

char* fr_asprint ( TALLOC_CTX *  ctx,
char const *  in,
ssize_t  inlen,
char  quote 
)

Escape string that may contain binary data, and write it to a new buffer.

This is useful in situations where we expect printable strings as input, but under some conditions may get binary data. A good example is libldap and the arrays of struct berval ldap_get_values_len returns.

Parameters
[in]ctxTo allocate new buffer in.
[in]inString to escape.
[in]inlenLength of string. Should be >= 0 if the data may contain embedded \0s. Must be >= 0 if data may not be \0 terminated. If < 0 inlen will be calculated using strlen.
[in]quotethe quotation character.
Returns
new buffer holding the escaped string.

Definition at line 428 of file print.c.

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

◆ fr_asprintf()

char* fr_asprintf ( TALLOC_CTX *  ctx,
char const *  fmt,
  ... 
)

Special version of asprintf which implements custom format specifiers.

Parameters
[in]ctxto allocate buffer in.
[in]fmtstring.
[in]...variadic argument list.
Returns
  • The result of string interpolation.

Definition at line 874 of file print.c.

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

◆ fr_fprintf()

ssize_t fr_fprintf ( FILE *  fp,
char const *  fmt,
  ... 
)

Special version of fprintf which implements custom format specifiers.

Parameters
[in]fpto write the result of fmt string.
[in]fmtstring.
[in]...variadic argument list.
Returns
  • On success, the number of bytes written is returned (zero indicates nothing was written).
  • On error, -1 is returned, and errno is set appropriately

Definition at line 897 of file print.c.

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

◆ fr_snprint()

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

Escape any non printable or non-UTF8 characters in the input string.

Note
Return value should be checked with is_truncated
Will always \0 terminate unless outlen == 0.
Parameters
[out]outwhere to write the escaped string.
[out]outlenthe length of the buffer pointed to by out.
[in]instring to escape.
[in]inlenlength of string to escape (lets us deal with embedded NULs)
[in]quotethe quotation character
Returns
  • The number of bytes written to the out buffer.
  • A number >= outlen if truncation has occurred.

Definition at line 227 of file print.c.

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

◆ fr_snprint_len()

size_t fr_snprint_len ( char const *  in,
ssize_t  inlen,
char  quote 
)

Find the length of the buffer required to fully escape a string with fr_prints.

Were assuming here that's it's cheaper to figure out the length and do one alloc than repeatedly expand the buffer when we find extra chars which need to be added.

Parameters
instring to calculate the escaped length for.
inlenlength of the input string, if < 0 strlen will be used to check the length.
[in]quotethe quotation character.
Returns
the size of buffer required to hold the escaped string including the NUL byte.

Definition at line 409 of file print.c.

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

◆ fr_utf8_char()

size_t fr_utf8_char ( uint8_t const *  str,
ssize_t  inlen 
)
inline

Checks for utf-8, taken from http://www.w3.org/International/questions/qa-forms-utf-8.

Parameters
[in]strinput string.
[in]inlenlength of input string. May be -1 if str is \0 terminated.
Returns
  • 0 if the character is invalid.
  • >0 the number of bytes the character consists of.

Definition at line 39 of file print.c.

+ Here is the caller graph for this function:

◆ fr_utf8_str()

fr_slen_t fr_utf8_str ( uint8_t const *  str,
ssize_t  inlen 
)

Validate a complete UTF8 string.

Parameters
[in]strinput string.
[in]inlenlength of input string. May be -1 if str is \0 terminated.
Returns
The number of bytes validated. If ret == inlen the entire string is valid. Else ret gives the negative offset at which the first invalid byte sequence was found.

Definition at line 143 of file print.c.

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

◆ fr_utf8_strchr()

char const* fr_utf8_strchr ( int *  out_chr_len,
char const *  str,
ssize_t  inlen,
char const *  chr 
)

Return a pointer to the first UTF8 char in a string.

Parameters
[out]out_chr_lenWhere to write the length of the multibyte char passed in chr (may be NULL).
[in]strHaystack.
[in]inlenLength of string (in bytes). Pass -1 to determine the length of the string.
[in]chrMultibyte needle.
Returns
  • Position of chr in str.
  • NULL if not found.

Definition at line 174 of file print.c.

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

◆ fr_vasprintf()

char* fr_vasprintf ( TALLOC_CTX *  ctx,
char const *  fmt,
va_list  ap 
)

Definition at line 851 of file print.c.

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

◆ fr_vasprintf_internal()

static char* fr_vasprintf_internal ( TALLOC_CTX *  ctx,
char const *  fmt,
va_list  ap,
bool  suppress_secrets 
)
static

Special version of vasprintf which implements custom format specifiers.

Todo:
Do something sensible with 'n$', though it's probably not actually used anywhere in our code base.
  • pV prints a value box as a string.
  • pM prints a list of value boxes, concatenating them.
  • pH prints a value box as a hex string.
  • pP prints a fr_pair_t.

This breaks strict compatibility with printf but allows us to continue using the static format string and argument type validation.

This same idea is used in Linux for the printk function.

Parameters
[in]ctxto allocate buffer in.
[in]fmtstring.
[in]apvariadic argument list.
[in]suppress_secretsas described
Returns
  • The result of string interpolation.
  • NULL if OOM.

Definition at line 473 of file print.c.

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

◆ fr_vasprintf_secure()

char* fr_vasprintf_secure ( TALLOC_CTX *  ctx,
char const *  fmt,
va_list  ap 
)

Definition at line 856 of file print.c.

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