23 RCSID(
"$Id: ae8a8f6668b6d155854898ffd05d932a6c8b564d $")
25 #include <freeradius-devel/util/debug.h>
26 #include <freeradius-devel/util/base16.h>
27 #include <freeradius-devel/util/pair.h>
41 if (
inlen == 0)
return 0;
45 if (*str < 0x20)
return 0;
47 if (*str <= 0x7e)
return 1;
49 if (*str <= 0xc1)
return 0;
51 if (
inlen < 2)
return 0;
53 if ((str[0] >= 0xc2) &&
60 if (
inlen < 3)
return 0;
62 if ((str[0] == 0xe0) &&
70 if ((str[0] >= 0xe1) &&
79 if ((str[0] >= 0xee) &&
88 if ((str[0] == 0xed) &&
96 if (
inlen < 4)
return 0;
98 if ((str[0] == 0xf0) &&
108 if ((str[0] >= 0xf1) &&
120 if ((str[0] == 0xf4) &&
159 if (clen == 0)
return end - p;
178 char const *p = str, *end;
190 if (needle_len == 0) needle_len = 1;
191 if (out_chr_len) *out_chr_len = needle_len;
201 if (schr_len == 0) schr_len = 1;
202 if (schr_len != needle_len)
goto next;
207 if (memcmp(p, chr, schr_len) == 0)
return p;
238 if (
out && outlen) *
out =
'\0';
252 if ((
size_t)
inlen >= outlen) {
253 memcpy(
out,
in, outlen - 1);
254 out[outlen - 1] =
'\0';
268 if (freespace == 0)
out = NULL;
269 if (!
out) freespace = 0;
322 if ((freespace > 0) && (freespace <= 2)) {
327 }
else if (freespace > 2) {
360 if ((freespace > 0) && (freespace <= 4)) {
365 }
else if (freespace > 4) {
377 if ((freespace > 0) && (freespace <= utf8)) {
382 }
else if (freespace > utf8) {
437 out = talloc_array(ctx,
char, len);
477 char const *p =
fmt, *end = p + strlen(
fmt), *fmt_p = p, *fmt_q = p;
478 char *
out = NULL, *out_tmp;
482 out = talloc_strdup(ctx,
"");
488 char len[2] = {
'\0',
'\0' };
492 if ((*p !=
'%') || (*++p ==
'%')) {
500 for (q = p; isdigit((
uint8_t) *q); q++);
501 if ((q != p) && (*q ==
'$')) {
535 if ((*p ==
'.') && (*(p + 1) ==
'*') && (*(p + 2) ==
's')) {
536 (void) va_arg(ap_q,
int);
538 }
else if (*p ==
'*') {
539 (void) va_arg(ap_q,
int);
542 for (q = p; isdigit((
uint8_t) *q); q++);
553 (void) strtoul(p, &r, 10);
564 if ((*p ==
'h') || (*p ==
'l')) len[1] = *p++;
588 (void) va_arg(ap_q,
int);
590 (void) va_arg(ap_q,
int);
595 if ((*p ==
'i') || (*p ==
'd')) {
597 (void) va_arg(ap_q,
long);
599 (void) va_arg(ap_q,
long long);
603 (void) va_arg(ap_q,
unsigned long);
605 (void) va_arg(ap_q,
unsigned long long);
611 (void) va_arg(ap_q,
size_t);
615 (void) va_arg(ap_q, intmax_t);
619 (void) va_arg(ap_q, ptrdiff_t);
623 if ((*p ==
'i') || (*p ==
'd')) {
624 (void) va_arg(ap_q,
int);
626 (void) va_arg(ap_q,
unsigned int);
641 (void) va_arg(ap_q,
long double);
646 (void) va_arg(ap_q,
double);
651 (void) va_arg(ap_q,
char *);
655 (void) va_arg(ap_q,
int);
676 if (*(p + 1) ==
'V') {
695 if (!subst)
goto oom;
702 if (fmt_q != fmt_p) {
705 sub_fmt = talloc_strndup(NULL, fmt_p, fmt_q - fmt_p);
706 out_tmp = talloc_vasprintf_append_buffer(
out, sub_fmt, ap_p);
719 out_tmp = talloc_strdup_append_buffer(
out, subst);
720 if (!out_tmp)
goto oom;
726 out_tmp = talloc_strdup_append_buffer(
out, subst);
727 if (!out_tmp)
goto oom;
743 subst = talloc_strdup(NULL,
"(null)");
752 subst = talloc_strdup(NULL,
"");
769 if (!subst)
goto oom;
782 fr_value_box_list_t
const *
in = va_arg(ap_q, fr_value_box_list_t
const *);
785 subst = talloc_strdup(NULL,
"(null)");
789 if (suppress_secrets) {
802 subst = talloc_strdup(NULL,
"(null)");
808 if (
unlikely(
in &&
in->data.secret && suppress_secrets)) {
817 (void) va_arg(ap_q,
void *);
822 (void) va_arg(ap_q,
int *);
835 out_tmp = talloc_vasprintf_append_buffer(
out, fmt_p, ap_p);
836 if (!out_tmp)
goto oom;
848 talloc_set_type(
out,
char);
914 ret = fputs(buf, fp);
static int const char * fmt
static fr_slen_t fr_base16_aencode(TALLOC_CTX *ctx, char **out, fr_dbuff_t *in)
Convert binary data to a hex string, allocating the output buffer.
#define FR_DBUFF_TMP(_start, _len_or_end)
Creates a compound literal to pass into functions which accept a dbuff.
#define fr_cond_assert(_x)
Calls panic_action ifndef NDEBUG, else logs error and evaluates to value of _x.
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_OCTETS
Raw octets.
ssize_t fr_fprintf(FILE *fp, char const *fmt,...)
Special version of fprintf which implements custom format specifiers.
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.
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.
char * fr_vasprintf(TALLOC_CTX *ctx, char const *fmt, va_list ap)
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.
ssize_t fr_utf8_str(uint8_t const *str, ssize_t inlen)
Validate a complete UTF8 string.
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.
char * fr_asprintf(TALLOC_CTX *ctx, char const *fmt,...)
Special version of asprintf which implements custom format specifiers.
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.
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.
char * fr_vasprintf_secure(TALLOC_CTX *ctx, char const *fmt, va_list ap)
PUBLIC int snprintf(char *string, size_t length, char *format, va_alist)
Stores an attribute, a value and various bits of other data.
char * talloc_typed_strdup(TALLOC_CTX *ctx, char const *p)
Call talloc_strdup, setting the type on the new chunk correctly.
static fr_slen_t fr_pair_aprint(TALLOC_CTX *ctx, char **out, fr_dict_attr_t const *parent, fr_pair_t const *vp) 1(fr_pair_print
static fr_slen_t static vp fr_slen_t fr_pair_aprint_secure(TALLOC_CTX *ctx, char **out, fr_dict_attr_t const *parent, fr_pair_t const *vp) 1(fr_pair_print_secure
char const * fr_strerror(void)
Get the last library error.
#define fr_strerror_const(_msg)
fr_sbuff_escape_rules_t fr_value_escape_double
int fr_value_box_cast(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t dst_type, fr_dict_attr_t const *dst_enumv, fr_value_box_t const *src)
Convert one type of fr_value_box_t to another.
char * fr_value_box_list_aprint(TALLOC_CTX *ctx, fr_value_box_list_t const *list, char const *delim, fr_sbuff_escape_rules_t const *e_rules)
Concatenate the string representations of a list of value boxes together.
void fr_value_box_clear(fr_value_box_t *data)
Clear/free any existing value and metadata.
char * fr_value_box_list_aprint_secure(TALLOC_CTX *ctx, fr_value_box_list_t const *list, char const *delim, fr_sbuff_escape_rules_t const *e_rules)
Concatenate the string representations of a list of value boxes together hiding "secret" values.
static fr_slen_t fr_value_box_aprint(TALLOC_CTX *ctx, char **out, fr_value_box_t const *data, fr_sbuff_escape_rules_t const *e_rules) 1(fr_value_box_print
static size_t char fr_sbuff_t size_t inlen
int format(printf, 5, 0))
static size_t char ** out