23 RCSID(
"$Id: e9fd3b0645e98181df408fd187d6e3ec460cfeab $")
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 <= 0x7f)
return 1;
47 if (*str <= 0xc1)
return 0;
49 if (
inlen < 2)
return 0;
51 if ((str[0] >= 0xc2) &&
58 if (
inlen < 3)
return 0;
60 if ((str[0] == 0xe0) &&
68 if ((str[0] >= 0xe1) &&
77 if ((str[0] >= 0xee) &&
86 if ((str[0] == 0xed) &&
94 if (
inlen < 4)
return 0;
96 if ((str[0] == 0xf0) &&
106 if ((str[0] >= 0xf1) &&
118 if ((str[0] == 0xf4) &&
157 if (clen == 0)
return p - end;
176 char const *p = str, *end;
188 if (needle_len == 0) needle_len = 1;
189 if (out_chr_len) *out_chr_len = needle_len;
199 if (schr_len == 0) schr_len = 1;
200 if (schr_len != needle_len)
goto next;
205 if (memcmp(p, chr, schr_len) == 0)
return p;
236 if (
out && outlen) *
out =
'\0';
250 if ((
size_t)
inlen >= outlen) {
251 memcpy(
out,
in, outlen - 1);
252 out[outlen - 1] =
'\0';
266 if (freespace == 0)
out = NULL;
267 if (!
out) freespace = 0;
320 if ((freespace > 0) && (freespace <= 2)) {
325 }
else if (freespace > 2) {
358 if ((freespace > 0) && (freespace <= 4)) {
363 }
else if (freespace > 4) {
375 if ((freespace > 0) && (freespace <= utf8)) {
380 }
else if (freespace > utf8) {
435 out = talloc_array(ctx,
char, len);
475 char const *p =
fmt, *end = p + strlen(
fmt), *fmt_p = p, *fmt_q = p;
476 char *
out = NULL, *out_tmp;
480 out = talloc_strdup(ctx,
"");
486 char len[2] = {
'\0',
'\0' };
490 if ((*p !=
'%') || (*++p ==
'%')) {
498 for (q = p; isdigit((
uint8_t) *q); q++);
499 if ((q != p) && (*q ==
'$')) {
533 if ((*p ==
'.') && (*(p + 1) ==
'*') && (*(p + 2) ==
's')) {
534 (void) va_arg(ap_q,
int);
536 }
else if (*p ==
'*') {
537 (void) va_arg(ap_q,
int);
540 for (q = p; isdigit((
uint8_t) *q); q++);
551 (void) strtoul(p, &r, 10);
562 if ((*p ==
'h') || (*p ==
'l')) len[1] = *p++;
586 (void) va_arg(ap_q,
int);
588 (void) va_arg(ap_q,
int);
593 if ((*p ==
'i') || (*p ==
'd')) {
595 (void) va_arg(ap_q,
long);
597 (void) va_arg(ap_q,
long long);
601 (void) va_arg(ap_q,
unsigned long);
603 (void) va_arg(ap_q,
unsigned long long);
609 (void) va_arg(ap_q,
size_t);
613 (void) va_arg(ap_q, intmax_t);
617 (void) va_arg(ap_q, ptrdiff_t);
621 if ((*p ==
'i') || (*p ==
'd')) {
622 (void) va_arg(ap_q,
int);
624 (void) va_arg(ap_q,
unsigned int);
639 (void) va_arg(ap_q,
long double);
644 (void) va_arg(ap_q,
double);
649 (void) va_arg(ap_q,
char *);
653 (void) va_arg(ap_q,
int);
674 if (*(p + 1) ==
'V') {
693 if (!subst)
goto oom;
700 if (fmt_q != fmt_p) {
703 sub_fmt = talloc_strndup(NULL, fmt_p, fmt_q - fmt_p);
704 out_tmp = talloc_vasprintf_append_buffer(
out, sub_fmt, ap_p);
717 out_tmp = talloc_strdup_append_buffer(
out, subst);
718 if (!out_tmp)
goto oom;
724 out_tmp = talloc_strdup_append_buffer(
out, subst);
725 if (!out_tmp)
goto oom;
741 subst = talloc_strdup(NULL,
"(null)");
750 subst = talloc_strdup(NULL,
"");
767 if (!subst)
goto oom;
780 fr_value_box_list_t
const *
in = va_arg(ap_q, fr_value_box_list_t
const *);
783 subst = talloc_strdup(NULL,
"(null)");
787 if (suppress_secrets) {
800 subst = talloc_strdup(NULL,
"(null)");
806 if (
unlikely(
in &&
in->data.secret && suppress_secrets)) {
815 (void) va_arg(ap_q,
void *);
820 (void) va_arg(ap_q,
int *);
833 out_tmp = talloc_vasprintf_append_buffer(
out, fmt_p, ap_p);
834 if (!out_tmp)
goto oom;
846 talloc_set_type(
out,
char);
912 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)
fr_slen_t fr_utf8_str(uint8_t const *str, ssize_t inlen)
Validate a complete UTF8 string.
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.
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