#include <time.h>
#include <math.h>
-#include <freeradius-devel/util/base.h>
-#include <freeradius-devel/util/event.h>
#include <freeradius-devel/autoconf.h>
+#include <freeradius-devel/radius/list.h>
+#include <freeradius-devel/util/base.h>
#include <freeradius-devel/util/conf.h>
+#include <freeradius-devel/util/event.h>
+#include <freeradius-devel/util/hex.h>
#include <freeradius-devel/util/pcap.h>
#include <freeradius-devel/util/timeval.h>
-#include <freeradius-devel/radius/list.h>
#ifdef HAVE_COLLECTDC_H
# include <collectd/client.h>
fr_pair_list_log(&default_log, packet->vps);
}
- fr_bin2hex(vector, packet->vector, RADIUS_AUTH_VECTOR_LENGTH);
+ fr_bin2hex(&FR_SBUFF_OUT(vector, sizeof(vector)),
+ &FR_DBUFF_TMP(packet->vector, RADIUS_AUTH_VECTOR_LENGTH));
INFO("\tAuthenticator-Field = 0x%s", vector);
}
}
USES_APPLE_DEPRECATED_API
#include <freeradius-devel/ldap/base.h>
+#include <freeradius-devel/util/hex.h>
#include <stdarg.h>
#include <ctype.h>
/*
* Hex encoding, consume three chars
*/
- if (fr_hex2bin((uint8_t *) &c, 1, p + 1, 2) == 1) {
+ if (fr_hex2bin(&FR_DBUFF_TMP((uint8_t *) &c, 1), &FR_SBUFF_IN(p + 1, 2)) == 1) {
inlen -= 2;
p += 2;
continue;
* special encoding, get rewritten to the
* special encoding.
*/
- if (fr_hex2bin((uint8_t *) &c, 1, p + 1, 2) == 1) {
+ if (fr_hex2bin(&FR_DBUFF_TMP((uint8_t *) &c, 1), &FR_SBUFF_IN(p + 1, 2)) == 1) {
switch (c) {
case ' ':
case '#':
*/
RCSID("$Id$")
+#include <freeradius-devel/protocol/freeradius/freeradius.internal.h>
+#include <freeradius-devel/server/cf_file.h>
#include <freeradius-devel/server/cf_parse.h>
#include <freeradius-devel/server/client.h>
#include <freeradius-devel/server/module.h>
-#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/server/virtual_servers.h>
-#include <freeradius-devel/server/cf_file.h>
-#include <freeradius-devel/protocol/freeradius/freeradius.internal.h>
+#include <freeradius-devel/util/debug.h>
+#include <freeradius-devel/util/hex.h>
#include <freeradius-devel/util/misc.h>
#include <freeradius-devel/util/trie.h>
hex_len = talloc_array_length(value) - 3;
bin_len = (hex_len / 2) + 1;
MEM(bin = talloc_array(c, uint8_t, bin_len));
- converted = fr_hex2bin(bin, bin_len, value + 2, hex_len);
+ converted = fr_hex2bin(&FR_DBUFF_TMP(bin, bin_len), &FR_SBUFF_IN(value + 2, hex_len));
if (converted < (bin_len - 1)) {
cf_log_err(cs, "Invalide hex string in shared secret");
goto error;
#include <freeradius-devel/server/exec.h>
#include <freeradius-devel/server/map.h>
#include <freeradius-devel/server/paircmp.h>
-#include <freeradius-devel/util/debug.h>
+#include <freeradius-devel/util/debug.h>
+#include <freeradius-devel/util/hex.h>
#include <freeradius-devel/util/misc.h>
#include <freeradius-devel/util/pair_cursor.h>
#include <freeradius-devel/util/pair_legacy.h>
ptr = talloc_array(map, uint8_t, len >> 1);
if (!ptr) return false;
- fr_hex2bin(ptr, len >> 1, rhs + 2, len);
+ fr_hex2bin(&FR_DBUFF_TMP(ptr, len >> 1), &FR_SBUFF_IN(rhs + 2, len));
/*
* Convert to da->type (if possible);
#include <freeradius-devel/server/password.h>
#include <freeradius-devel/util/base64.h>
+#include <freeradius-devel/util/hex.h>
#include <freeradius-devel/util/md4.h>
#include <freeradius-devel/util/md5.h>
#include <freeradius-devel/util/misc.h>
if (!(len & 0x01) && len >= (2 * min_len)) {
size_t decoded;
- decoded = fr_hex2bin(buffer, bufflen, known_good, len);
+ decoded = fr_hex2bin(&FR_DBUFF_TMP(buffer, bufflen), &FR_SBUFF_IN(known_good, len));
if (decoded == (len >> 1)) {
if (action) *action = NORMALISED_HEX;
return decoded;
#include <freeradius-devel/server/tmpl.h>
#include <freeradius-devel/server/base.h>
-#include <freeradius-devel/util/debug.h>
+#include <freeradius-devel/util/debug.h>
+#include <freeradius-devel/util/hex.h>
#include <freeradius-devel/util/misc.h>
#include <ctype.h>
vpt = tmpl_alloc(ctx, TMPL_TYPE_DATA, in, inlen, type);
(void)fr_value_box_mem_alloc(vpt, &bin, &vpt->data.literal, NULL, binlen, false);
- len = fr_hex2bin(bin, binlen, in + 2, inlen - 2);
+ len = fr_hex2bin(&FR_DBUFF_TMP(bin, binlen), &FR_SBUFF_IN(in + 2, inlen - 2));
if (len != binlen) {
fr_strerror_printf("Hex string contains non-hex char");
talloc_free(vpt);
RCSID("$Id$")
+
#include <freeradius-devel/server/base.h>
-#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/server/stats.h>
#include <freeradius-devel/server/util.h>
+#include <freeradius-devel/util/debug.h>
+#include <freeradius-devel/util/hex.h>
#include <freeradius-devel/util/misc.h>
#include <ctype.h>
* Unsafe chars
*/
*out++ = '-';
- fr_bin2hex(out, (uint8_t const *)in++, 1);
+ in++;
+ fr_bin2hex(&FR_SBUFF_OUT(out, freespace), &FR_DBUFF_TMP((uint8_t const *)in, 1));
out += 2;
freespace -= 3;
}
/*
* If hex2bin returns 0 the next two chars weren't hexits.
*/
- if (fr_hex2bin((uint8_t *) out, 1, in, 1) == 0) return in - (p + 1);
+ if (fr_hex2bin(&FR_DBUFF_TMP((uint8_t *) out, 1), &FR_SBUFF_IN(in, 1)) == 0) return in - (p + 1);
in += 2;
out++;
freespace--;
#ifdef WITH_TLS
#define LOG_PREFIX "tls - "
+#include <freeradius-devel/util/debug.h>
+#include <freeradius-devel/util/hex.h>
#include <freeradius-devel/util/misc.h>
#include <freeradius-devel/util/syserror.h>
-#include <freeradius-devel/util/debug.h>
#include <openssl/rand.h>
#include <openssl/dh.h>
* Check the password now, so that we don't have
* errors at run-time.
*/
- hex_len = fr_hex2bin(buffer, sizeof(buffer), conf->psk_password, psk_len);
+ hex_len = fr_hex2bin(&FR_DBUFF_TMP(buffer, sizeof(buffer)), &FR_SBUFF_IN(conf->psk_password, psk_len));
if (psk_len != (2 * hex_len)) {
ERROR("psk_hexphrase is not all hex");
goto error;
goto error;
}
X509_STORE_set_flags(cert_vpstore, X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL);
-#ifdef X509_V_FLAG_USE_DELTAS
+#ifdef X509_V_FLAG_USE_DELTAS
/*
* If set, delta CRLs (if present) are used to
* determine certificate status. If not set
#ifdef HAVE_OPENSSL_OCSP_H
#define LOG_PREFIX "tls - "
-#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/server/pair.h>
+#include <freeradius-devel/util/debug.h>
+#include <freeradius-devel/util/hex.h>
#include <freeradius-devel/util/misc.h>
#include <freeradius-devel/util/pair_legacy.h>
strlcpy(identity, conf->psk_identity, max_identity_len);
- return fr_hex2bin(psk, max_psk_len, conf->psk_password, psk_len);
+ return fr_hex2bin(&FR_DBUFF_TMP((uint8_t *)psk, (size_t)max_psk_len),
+ &FR_SBUFF_IN(conf->psk_password, (size_t)psk_len));
}
/** Determine the PSK to use for an incoming connection
* - >0 if a PSK matching identity was found (the length of bytes written to psk).
*/
unsigned int fr_tls_session_psk_server_cb(SSL *ssl, const char *identity,
- unsigned char *psk, unsigned int max_psk_len)
+ unsigned char *psk, unsigned int max_psk_len)
{
- unsigned int psk_len = 0;
+ size_t psk_len = 0;
fr_tls_conf_t *conf;
REQUEST *request;
* convert the expansion from printable string
* back to hex.
*/
- return fr_hex2bin(psk, max_psk_len, buffer, hex_len);
+ return fr_hex2bin(&FR_DBUFF_TMP((uint8_t *)psk, (size_t)max_psk_len), &FR_SBUFF_IN(buffer, hex_len));
}
if (!conf->psk_identity) {
psk_len = strlen(conf->psk_password);
if (psk_len > (2 * max_psk_len)) return 0;
- return fr_hex2bin(psk, max_psk_len, conf->psk_password, psk_len);
+ return fr_hex2bin(&FR_DBUFF_TMP((uint8_t *)psk, (size_t)max_psk_len), &FR_SBUFF_IN(conf->psk_password, psk_len));
}
#endif /* PSK_MAX_IDENTITY_LEN */
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/server/cond.h>
-#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/server/regex.h>
#include <freeradius-devel/unlang/xlat_priv.h>
#include <freeradius-devel/util/base64.h>
+#include <freeradius-devel/util/debug.h>
+#include <freeradius-devel/util/hex.h>
#include <freeradius-devel/util/md5.h>
#include <freeradius-devel/util/misc.h>
#include <freeradius-devel/util/rand.h>
MEM(result = fr_value_box_alloc_null(ctx));
MEM(fr_value_box_mem_alloc(result, &bin, result, NULL, outlen, fr_value_box_list_tainted(*in)) == 0);
- fr_hex2bin(bin, outlen, p, end - p);
+ fr_hex2bin(&FR_DBUFF_TMP(bin, outlen), &FR_SBUFF_IN(p, end - p));
fr_cursor_append(out, result);
MEM(vb = fr_value_box_alloc(ctx, FR_TYPE_STRING, NULL, false));
vb->vb_length = ((*in)->vb_length * 2);
vb->vb_strvalue = p = talloc_zero_array(vb, char, vb->vb_length + 1);
- fr_bin2hex(p, (*in)->vb_octets, (*in)->vb_length);
+ fr_bin2hex(&FR_SBUFF_OUT(p, talloc_array_length(p)), &FR_DBUFF_TMP((*in)->vb_octets, (*in)->vb_length));
fr_cursor_append(out, vb);
#ifdef WITH_ASCEND_BINARY
#include "ascend.h"
+#include <freeradius-devel/util/hex.h>
#include <freeradius-devel/util/misc.h>
#include <freeradius-devel/util/talloc.h>
/*
* Node must be 6 octets long.
*/
- token = fr_hex2bin(net->node, IPX_NODE_ADDR_LEN, p, strlen(p));
+ token = fr_hex2bin(&FR_DBUFF_TMP(net->node, IPX_NODE_ADDR_LEN), &FR_SBUFF_IN(p, strlen(p)));
if (token != IPX_NODE_ADDR_LEN) return -1;
/*
filter->offset = rcode;
filter->offset = htons(filter->offset);
- rcode = fr_hex2bin(filter->mask, sizeof(filter->mask), argv[1], strlen(argv[1]));
+ rcode = fr_hex2bin(&FR_DBUFF_TMP(filter->mask, sizeof(filter->mask)), &FR_SBUFF_IN(argv[1], strlen(argv[1])));
if (rcode != sizeof(filter->mask)) return -1;
- token = fr_hex2bin(filter->value, sizeof(filter->value), argv[2], strlen(argv[2]));
+ token = fr_hex2bin(&FR_DBUFF_TMP(filter->value, sizeof(filter->value)), &FR_SBUFF_IN(argv[2], strlen(argv[2])));
if (token != sizeof(filter->value)) return -1;
filter->len = rcode;
(uint8_t const *)(_start), \
_Generic((_len_or_end), \
size_t : (uint8_t const *)(_start) + (size_t)(_len_or_end), \
+ long : (uint8_t const *)(_start) + (size_t)(_len_or_end), \
+ int : (uint8_t const *)(_start) + (size_t)(_len_or_end), \
+ unsigned int : (uint8_t const *)(_start) + (size_t)(_len_or_end), \
uint8_t * : (uint8_t const *)(_len_or_end), \
uint8_t const * : (uint8_t const *)(_len_or_end), \
char * : (uint8_t const *)(_len_or_end), \
.start_i = (uint8_t const *)(_start), \
.end_i = _Generic((_len_or_end), \
size_t : (uint8_t const *)(_start) + (size_t)(_len_or_end), \
+ long : (uint8_t const *)(_start) + (size_t)(_len_or_end), \
+ int : (uint8_t const *)(_start) + (size_t)(_len_or_end), \
+ unsigned int : (uint8_t const *)(_start) + (size_t)(_len_or_end), \
uint8_t * : (uint8_t const *)(_len_or_end), \
uint8_t const * : (uint8_t const *)(_len_or_end), \
char * : (uint8_t const *)(_len_or_end), \
--- /dev/null
+/*
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/** A generic string buffer structure for string printing and parsing
+ *
+ * @file src/lib/util/sbuff.c
+ *
+ * @copyright 2020 Arran Cudbard-Bell \<a.cudbardb@freeradius.org\>
+ */
+RCSID("$Id$")
+
+#include <freeradius-devel/util/hex.h>
+
+static char const hextab[] = "0123456789abcdef";
+
+/** Convert hex strings to binary data
+ *
+ * @param[out] out Output buffer to write to.
+ * @param[in] in Input string.
+ * @return
+ * - >=0 the number of bytes written to out.
+ * - <0 number of bytes we would have needed to copy the next hexit.
+ */
+ssize_t fr_hex2bin(fr_dbuff_t *out, fr_sbuff_t *in)
+{
+ size_t total = 0;
+
+ while (!FR_SBUFF_CANT_EXTEND_LOWAT(in, 2)) {
+ char *c1, *c2;
+
+ if(!(c1 = memchr(hextab, tolower((int) *in->p), sizeof(hextab))) ||
+ !(c2 = memchr(hextab, tolower((int) *(in->p + 1)), sizeof(hextab)))) break;
+
+ FR_DBUFF_BYTES_IN_RETURN(out, ((c1 - hextab) << 4) + (c2 - hextab));
+
+ fr_sbuff_advance(in, 2);
+ total++;
+ };
+
+ return total;
+}
+
+/** Convert binary data to a hex string
+ *
+ * Ascii encoded hex string will not be prefixed with '0x'
+ *
+ * @warning If the output buffer isn't long enough, we have a buffer overflow.
+ *
+ * @param[out] out Output buffer to write to.
+ * @param[in] in input.
+ * @return
+ * - >=0 the number of bytes written to out.
+ * - <0 number of bytes we would have needed to print the next hexit.
+ */
+ssize_t fr_bin2hex(fr_sbuff_t *out, fr_dbuff_t *in)
+{
+ size_t total = 0;
+
+ while (fr_dbuff_remaining(in) > 0) { /* Fixme to be extension check */
+ FR_SBUFF_IN_CHAR_RETURN(out, hextab[((*in->p) >> 4) & 0x0f], hextab[*in->p & 0x0f]);
+
+ fr_dbuff_advance(in, 1);
+ total += 2;
+ };
+ return total;
+}
+
+/** Convert binary data to a hex string
+ *
+ * Ascii encoded hex string will not be prefixed with '0x'
+ *
+ * @param[in] ctx to alloc buffer in.
+ * @param[in] bin input.
+ * @param[in] inlen of bin input.
+ * @return length of data written to buffer.
+ */
+char *fr_abin2hex(TALLOC_CTX *ctx, uint8_t const *bin, size_t inlen)
+{
+ char *buff;
+
+ buff = talloc_array(ctx, char, (inlen << 2));
+ if (!buff) return NULL;
+
+ fr_bin2hex(&FR_SBUFF_OUT(buff, (inlen * 2) + 1), &FR_DBUFF_TMP(bin, inlen));
+
+ return buff;
+}
--- /dev/null
+#pragma once
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/** A generic buffer structure for string printing and parsing strings
+ *
+ * Because doing manual length checks is error prone and a waste of everyones time.
+ *
+ * @file src/lib/util/sbuff.h
+ *
+ * @copyright 2020 Arran Cudbard-Bell <a.cudbardb@freeradius.org>
+ */
+RCSIDH(hex_h, "$Id$")
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+#include <sys/types.h>
+#include <freeradius-devel/util/sbuff.h>
+#include <freeradius-devel/util/dbuff.h>
+
+ssize_t fr_hex2bin(fr_dbuff_t *out, fr_sbuff_t *in);
+
+ssize_t fr_bin2hex(fr_sbuff_t *out, fr_dbuff_t *in);
+
+char *fr_abin2hex(TALLOC_CTX *ctx, uint8_t const *bin, size_t inlen);
+
+#ifdef __cplusplus
+}
+#endif
getaddrinfo.c \
hash.c \
heap.c \
+ hex.c \
hmac_md5.c \
hmac_sha1.c \
hw.c \
*/
RCSID("$Id$")
+#include <freeradius-devel/util/dbuff.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/misc.h>
+#include <freeradius-devel/util/sbuff.h>
#include <freeradius-devel/util/strerror.h>
#include <freeradius-devel/util/syserror.h>
#include <freeradius-devel/util/talloc.h>
return rad_lock(fd, lock_len, F_SETLK, F_UNLCK);
}
-static char const hextab[] = "0123456789abcdef";
-
-/** Convert hex strings to binary data
- *
- * @param bin Buffer to write output to.
- * @param outlen length of output buffer (or length of input string / 2).
- * @param hex input string.
- * @param inlen length of the input string
- * @return length of data written to buffer.
- */
-size_t fr_hex2bin(uint8_t *bin, size_t outlen, char const *hex, size_t inlen)
-{
- size_t i;
- size_t len;
- char *c1, *c2;
-
- /*
- * Smartly truncate output, caller should check number of bytes
- * written.
- */
- len = inlen >> 1;
- if (len > outlen) len = outlen;
-
- for (i = 0; i < len; i++) {
- if(!(c1 = memchr(hextab, tolower((int) hex[i << 1]), sizeof(hextab))) ||
- !(c2 = memchr(hextab, tolower((int) hex[(i << 1) + 1]), sizeof(hextab))))
- break;
- bin[i] = ((c1-hextab)<<4) + (c2-hextab);
- }
-
- return i;
-}
-
-/** Convert binary data to a hex string
- *
- * Ascii encoded hex string will not be prefixed with '0x'
- *
- * @warning If the output buffer isn't long enough, we have a buffer overflow.
- *
- * @param[out] hex Buffer to write hex output.
- * @param[in] bin input.
- * @param[in] inlen of bin input.
- * @return length of data written to buffer.
- */
-size_t fr_bin2hex(char *hex, uint8_t const *bin, size_t inlen)
-{
- size_t i;
-
- for (i = 0; i < inlen; i++) {
- hex[0] = hextab[((*bin) >> 4) & 0x0f];
- hex[1] = hextab[*bin & 0x0f];
- hex += 2;
- bin++;
- }
-
- *hex = '\0';
- return inlen * 2;
-}
-
-/** Convert binary data to a hex string
- *
- * Ascii encoded hex string will not be prefixed with '0x'
- *
- * @param[in] ctx to alloc buffer in.
- * @param[in] bin input.
- * @param[in] inlen of bin input.
- * @return length of data written to buffer.
- */
-char *fr_abin2hex(TALLOC_CTX *ctx, uint8_t const *bin, size_t inlen)
-{
- char *buff;
-
- buff = talloc_array(ctx, char, (inlen << 2));
- if (!buff) return NULL;
-
- fr_bin2hex(buff, bin, inlen);
-
- return buff;
-}
-
/** Consume the integer (or hex) portion of a value string
*
* Allows integer or hex representations of integers (but not octal,
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);
-char *fr_abin2hex(TALLOC_CTX *ctx, uint8_t const *bin, size_t inlen);
-size_t fr_bin2hex(char * restrict hex, uint8_t const * restrict bin, size_t inlen);
-size_t fr_hex2bin(uint8_t *bin, size_t outlen, char const *hex, size_t inlen);
int fr_strtoull(uint64_t *out, char **end, char const *value);
int fr_strtoll(int64_t *out, char **end, char const *value);
char *fr_trim(char const *str, size_t size);
#include <freeradius-devel/util/misc.h>
#include <freeradius-devel/util/pair.h>
#include <freeradius-devel/util/print.h>
+#include <freeradius-devel/util/hex.h>
#include <freeradius-devel/util/strerror.h>
#include <freeradius-devel/util/talloc.h>
case FR_TYPE_OCTETS:
subst = talloc_array(NULL, char, (in->vb_length * 2) + 1);
if (!subst) goto oom;
- fr_bin2hex(subst, in->vb_octets, in->vb_length);
+ fr_bin2hex(&FR_SBUFF_OUT(subst, talloc_array_length(subst)), &FR_DBUFF_TMP(in->vb_octets, in->vb_length));
break;
case FR_TYPE_STRING:
subst = talloc_array(NULL, char, (in->vb_length * 2) + 1);
if (!subst) goto oom;
- fr_bin2hex(subst, (uint8_t const *)in->vb_strvalue, in->vb_length);
+ fr_bin2hex(&FR_SBUFF_OUT(subst, talloc_array_length(subst)), &FR_DBUFF_TMP((uint8_t const *)in->vb_strvalue, in->vb_length));
break;
default:
subst = talloc_array(NULL, char, (dst.vb_length * 2) + 1);
if (!subst) goto oom;
- fr_bin2hex(subst, dst.vb_octets, dst.vb_length);
+ fr_bin2hex(&FR_SBUFF_OUT(subst, talloc_array_length(subst)), &FR_DBUFF_TMP(dst.vb_octets, dst.vb_length));
fr_value_box_clear(&dst);
break;
SBUFF_PARSE_FLOAT_DEF(float32, float, strtof, 100);
SBUFF_PARSE_FLOAT_DEF(float64, double, strtod, 100);
-/** Copy char into the sbuff
- *
- * @param[in] sbuff to copy into.
- * @param[in] c to copy into buffer.
- * @return
- * - >= 0 the number of bytes copied into the sbuff.
- * - <0 the number of bytes required to complete the copy operation.
- */
-ssize_t fr_sbuff_in_char(fr_sbuff_t *sbuff, char c)
-{
- CHECK_SBUFF_INIT(sbuff);
-
- if (unlikely(sbuff->is_const)) return 0;
-
- FR_SBUFF_EXTEND_OR_RETURN(sbuff, 1);
-
- *sbuff->p = c;
- *(sbuff->p + 1) = '\0';
-
- return fr_sbuff_advance(sbuff, 1);
-}
-
/** Copy bytes into the sbuff up to the first \0
*
* @param[in] sbuff to copy into.
size_t : (char const *)(_start) + ((size_t)(_len_or_end) - 1), \
long : (char const *)(_start) + ((size_t)(_len_or_end) - 1), \
int : (char const *)(_start) + ((size_t)(_len_or_end) - 1), \
+ unsigned int : (char const *)(_start) + ((size_t)(_len_or_end) - 1), \
char * : (char const *)(_len_or_end), \
char const * : (char const *)(_len_or_end) \
), \
size_t : (char const *)(_start) + (size_t)(_len_or_end), \
long : (char const *)(_start) + (size_t)(_len_or_end), \
int : (char const *)(_start) + (size_t)(_len_or_end), \
+ unsigned int : (char const *)(_start) + (size_t)(_len_or_end), \
char * : (char const *)(_len_or_end), \
char const * : (char const *)(_len_or_end) \
), \
*
* @{
*/
-ssize_t fr_sbuff_in_char(fr_sbuff_t *sbuff, char c);
-#define FR_SBUFF_IN_CHAR_RETURN(...) FR_SBUFF_RETURN(fr_sbuff_in_char, ##__VA_ARGS__)
+#define fr_sbuff_in_char(_sbuff, ...) fr_sbuff_in_bstrncpy(_sbuff, ((char []){ __VA_ARGS__ }), sizeof((char []){ __VA_ARGS__ }))
+#define FR_SBUFF_IN_CHAR_RETURN(_sbuff, ...) FR_SBUFF_RETURN(fr_sbuff_in_bstrncpy, _sbuff, ((char []){ __VA_ARGS__ }), sizeof((char []){ __VA_ARGS__ }))
ssize_t fr_sbuff_in_strcpy(fr_sbuff_t *sbuff, char const *str);
#define FR_SBUFF_IN_STRCPY_RETURN(...) FR_SBUFF_RETURN(fr_sbuff_in_strcpy, ##__VA_ARGS__)
#include <freeradius-devel/util/ascend.h>
#include <freeradius-devel/util/cursor.h>
#include <freeradius-devel/util/dbuff.h>
-#include <freeradius-devel/util/misc.h>
+#include <freeradius-devel/util/hex.h>
+#include <freeradius-devel/util/net.h>
#include <freeradius-devel/util/strerror.h>
#include <freeradius-devel/util/talloc.h>
-#include <freeradius-devel/util/net.h>
#include <assert.h>
#include <ctype.h>
ret = len >> 1;
p = talloc_array(ctx, uint8_t, ret);
- if (fr_hex2bin(p, ret, in + 2, len) != (size_t)ret) {
+ if (fr_hex2bin(&FR_DBUFF_TMP(p, ret), &FR_SBUFF_IN(in + 2, len)) != (ssize_t)ret) {
talloc_free(p);
fr_strerror_printf("Invalid hex data");
return -1;
return -1;
}
- bin = fr_hex2bin((uint8_t *) &dst->datum.filter, ret, in + 2, len - 2);
+ bin = fr_hex2bin(&FR_DBUFF_TMP((uint8_t *) &dst->datum.filter, (len - 2) / 2), &FR_SBUFF_IN(in + 2, len - 2));
if (bin < ret) {
memset(((uint8_t *) &dst->datum.filter) + bin, 0, ret - bin);
}
p[0] = '0';
p[1] = 'x';
- if (data->vb_octets) {
- fr_bin2hex(p + 2, data->vb_octets, data->datum.length);
+ if (data->vb_octets && data->datum.length) {
+ fr_bin2hex(&FR_SBUFF_OUT(p + 2, (data->datum.length * 2) + 1), &FR_DBUFF_TMP(data->vb_octets, data->datum.length));
p[2 + (data->datum.length * 2)] = '\0';
} else {
p[2] = '\0';
}
/* Get maximum number of uint8s we can encode given (end - p) */
- if (data->vb_octets) {
+ if (data->vb_octets && data->datum.length) {
max = (((end - p) % 2) ? (end - p) - 1 : (end - p) - 2) / 2;
- fr_bin2hex(p, data->vb_octets,
- ((size_t)data->datum.length > max) ? max : (size_t)data->datum.length);
+ fr_bin2hex(&FR_SBUFF_OUT(p, end),
+ &FR_DBUFF_TMP(data->vb_octets,
+ (size_t)data->datum.length > max ? max : (size_t)data->datum.length));
} else {
*p = '\0';
}
#include <freeradius-devel/unlang/base.h>
#include <freeradius-devel/util/event.h>
+#include <freeradius-devel/util/hex.h>
#include <freeradius-devel/util/md5.h>
-#include <freeradius-devel/util/misc.h>
#include <freeradius-devel/util/rand.h>
#include <freeradius-devel/util/sha1.h>
#include <freeradius-devel/util/socket.h>
return -1;
}
- return fr_hex2bin(secret, BFD_MAX_SECRET_LENGTH, value + 2, (len - 2));
+ return fr_hex2bin(&FR_DBUFF_TMP(secret, BFD_MAX_SECRET_LENGTH), &FR_SBUFF_IN(value + 2, (len - 2)));
}
if (len >= 20) {
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/server/module.h>
+
+#include <freeradius-devel/util/hex.h>
#include <freeradius-devel/util/md5.h>
typedef struct {
* Set A1 to Digest-HA1 if no User-Password found
*/
if (passwd->da == attr_digest_ha1) {
- if (fr_hex2bin(&a1[0], sizeof(a1), passwd->vp_strvalue, passwd->vp_length) != 16) {
+ if (fr_hex2bin(&FR_DBUFF_TMP(&a1[0], sizeof(a1)), &FR_SBUFF_IN(passwd->vp_strvalue, passwd->vp_length)) != 16) {
RDEBUG2("Invalid text in Digest-HA1");
return RLM_MODULE_INVALID;
}
*/
if (passwd->da == attr_cleartext_password) {
fr_md5_calc(hash, &a1[0], a1_len);
- fr_bin2hex((char *) &a1[0], hash, 16);
+ fr_bin2hex(&FR_SBUFF_OUT((char *) &a1[0], 32 + 1), &FR_DBUFF_TMP(hash, 16));
} else { /* MUST be Digest-HA1 */
memcpy(&a1[0], passwd->vp_strvalue, 32);
}
} else {
memcpy(&hash[0], &a1[0], a1_len);
}
- fr_bin2hex((char *) kd, hash, sizeof(hash));
+ fr_bin2hex(&FR_SBUFF_OUT((char *) kd, (sizeof(hash) * 2) + 1), &FR_DBUFF_TMP(hash, sizeof(hash)));
RHEXDUMP_INLINE3(hash, sizeof(hash), "H(A1)");
fr_md5_calc(&hash[0], &a2[0], a2_len);
- fr_bin2hex((char *) kd + kd_len, hash, sizeof(hash));
+ fr_bin2hex(&FR_SBUFF_OUT((char *) kd + kd_len, (sizeof(hash) * 2) + 1), &FR_DBUFF_TMP(hash, sizeof(hash)));
RHEXDUMP_INLINE3(hash, sizeof(hash), "H(A2)");
return RLM_MODULE_INVALID;
}
- if (fr_hex2bin(&hash[0], sizeof(hash), vp->vp_strvalue, vp->vp_length) != (vp->vp_length >> 1)) {
+ if (fr_hex2bin(&FR_DBUFF_TMP(&hash[0], sizeof(hash)), &FR_SBUFF_IN(vp->vp_strvalue, vp->vp_length)) != (vp->vp_length >> 1)) {
RDEBUG2("Invalid text in Digest-Response");
return RLM_MODULE_INVALID;
}
RCSID("$Id$")
-#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/unlang/base.h>
+#include <freeradius-devel/util/debug.h>
+#include <freeradius-devel/util/hex.h>
#include "eap_mschapv2.h"
if (n == 3) {
RDEBUG2("Found new challenge from MS-CHAP-Error: err=%d retry=%d challenge=%s",
err, retry, buf);
- fr_hex2bin(data->auth_challenge, 16, buf, strlen(buf));
+ fr_hex2bin(&FR_DBUFF_TMP(data->auth_challenge, 16), &FR_SBUFF_IN(buf, strlen(buf)));
} else {
RDEBUG2("Could not parse new challenge from MS-CHAP-Error: %d", n);
}
#include <freeradius-devel/server/password.h>
#include <freeradius-devel/util/debug.h>
+#include <freeradius-devel/util/hex.h>
#include <freeradius-devel/util/md4.h>
#include <freeradius-devel/util/md5.h>
#include <freeradius-devel/util/misc.h>
return -1;
}
- fr_bin2hex(*out, buffer, NT_DIGEST_LENGTH);
+ fr_bin2hex(&FR_SBUFF_OUT(*out, (NT_DIGEST_LENGTH * 2) + 1), &FR_DBUFF_TMP(buffer, NT_DIGEST_LENGTH));
(*out)[32] = '\0';
RDEBUG2("NT-Hash of \"known-good\" password: %s", *out);
return 32;
fr_skip_whitespace(p);
smbdes_lmpwdhash(p, buffer);
- fr_bin2hex(*out, buffer, LM_DIGEST_LENGTH);
+ fr_bin2hex(&FR_SBUFF_OUT(*out, (LM_DIGEST_LENGTH * 2) + 1), &FR_DBUFF_TMP(buffer, LM_DIGEST_LENGTH));
(*out)[32] = '\0';
RDEBUG2("LM-Hash of %s = %s", p, *out);
return 32;
/* now the password blobs */
len = sprintf(buf, "new-nt-password-blob: ");
- fr_bin2hex(buf+len, new_nt_password, 516);
+ fr_bin2hex(&FR_SBUFF_OUT(buf + len, sizeof(buf) - len), &FR_DBUFF_TMP(new_nt_password, 516));
buf[len+1032] = '\n';
buf[len+1033] = '\0';
len = strlen(buf);
}
len = sprintf(buf, "old-nt-hash-blob: ");
- fr_bin2hex(buf+len, old_nt_hash, NT_DIGEST_LENGTH);
+ fr_bin2hex(&FR_SBUFF_OUT(buf + len, sizeof(buf) - len), &FR_DBUFF_TMP(old_nt_hash, NT_DIGEST_LENGTH));
buf[len+32] = '\n';
buf[len+33] = '\0';
len = strlen(buf);
/*
* Update the NT hash hash, from the NT key.
*/
- if (fr_hex2bin(nthashhash, NT_DIGEST_LENGTH, buffer + 8, len) != NT_DIGEST_LENGTH) {
+ if (fr_hex2bin(&FR_DBUFF_TMP(nthashhash, NT_DIGEST_LENGTH), &FR_SBUFF_IN(buffer + 8, len)) != NT_DIGEST_LENGTH) {
REDEBUG("Invalid output from ntlm_auth: NT_KEY has non-hex values");
return -1;
}
#include <freeradius-devel/server/crypt.h>
#include <freeradius-devel/server/module.h>
#include <freeradius-devel/server/password.h>
-#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/tls/base.h>
+
#include <freeradius-devel/util/base64.h>
+#include <freeradius-devel/util/debug.h>
+#include <freeradius-devel/util/hex.h>
#include <freeradius-devel/util/md5.h>
#include <freeradius-devel/util/sha1.h>
len = xlat_eval(charbuf, sizeof(charbuf), request, "%{mschap:LM-Hash %{User-Password}}", NULL, NULL);
if (len < 0) return RLM_MODULE_FAIL;
- if ((fr_hex2bin(digest, sizeof(digest), charbuf, len) != known_good->vp_length) ||
+ if ((fr_hex2bin(&FR_DBUFF_TMP(digest, sizeof(digest)), &FR_SBUFF_IN(charbuf, len)) != (ssize_t)known_good->vp_length) ||
(fr_digest_cmp(digest, known_good->vp_octets, known_good->vp_length) != 0)) {
REDEBUG("LM digest does not match \"known good\" digest");
REDEBUG3("Calculated : %pH", fr_box_octets(digest, sizeof(digest)));
/*
* Sanity check the value of NS-MTA-MD5-Password
*/
- if (fr_hex2bin(digest, sizeof(digest), known_good->vp_strvalue, known_good->vp_length) != 16) {
+ if (fr_hex2bin(&FR_DBUFF_TMP(digest, sizeof(digest)), &FR_SBUFF_IN(known_good->vp_strvalue, known_good->vp_length)) != 16) {
REDEBUG("\"known good\" NS-MTA-MD5-Password has invalid value");
return RLM_MODULE_INVALID;
}
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/server/module.h>
#include <freeradius-devel/server/modpriv.h>
+
#include <freeradius-devel/util/debug.h>
+#include <freeradius-devel/util/hex.h>
#include <freeradius-devel/redis/base.h>
#include <freeradius-devel/redis/cluster.h>
fr_sha1_init(&sha1_ctx);
fr_sha1_update(&sha1_ctx, (uint8_t const *)lua_alloc_cmd, sizeof(lua_alloc_cmd) - 1);
fr_sha1_final(digest, &sha1_ctx);
- fr_bin2hex(lua_alloc_digest, digest, sizeof(digest));
+ fr_bin2hex(&FR_SBUFF_OUT(lua_alloc_digest, sizeof(lua_alloc_digest)), &FR_DBUFF_TMP(digest, sizeof(digest)));
fr_sha1_init(&sha1_ctx);
fr_sha1_update(&sha1_ctx, (uint8_t const *)lua_update_cmd, sizeof(lua_update_cmd) - 1);
fr_sha1_final(digest, &sha1_ctx);
- fr_bin2hex(lua_update_digest, digest, sizeof(digest));
+ fr_bin2hex(&FR_SBUFF_OUT(lua_update_digest, sizeof(lua_update_digest)), &FR_DBUFF_TMP(digest, sizeof(digest)));
fr_sha1_init(&sha1_ctx);
fr_sha1_update(&sha1_ctx, (uint8_t const *)lua_release_cmd, sizeof(lua_release_cmd) - 1);
fr_sha1_final(digest, &sha1_ctx);
- fr_bin2hex(lua_release_digest, digest, sizeof(digest));
+ fr_bin2hex(&FR_SBUFF_OUT(lua_release_digest, sizeof(lua_release_digest)), &FR_DBUFF_TMP(digest, sizeof(digest)));
}
/*
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/server/module.h>
+
+#include <freeradius-devel/util/hex.h>
+
#include <ctype.h>
static fr_dict_t const *dict_freeradius;
goto nothing;
}
input = blob;
- input_len = fr_hex2bin(blob, sizeof(blob), data_name + 2, len);
+ input_len = fr_hex2bin(&FR_DBUFF_TMP(blob, sizeof(blob)), &FR_SBUFF_IN(data_name + 2, len));
} else {
GOTO_ERROR;
#include <freeradius-devel/server/module.h>
#include <freeradius-devel/tls/base.h>
#include <freeradius-devel/tls/missing.h>
+#include <freeradius-devel/util/hex.h>
/*
* FIXME: Add check for this header to configure.ac
* so we fix it here.
*/
for (i = 0; i < 6; i++) {
- fr_bin2hex(&p[i * 3], &buffer[i], 1);
+ fr_bin2hex(&FR_SBUFF_OUT(&p[i * 3], 2 + 1), &FR_DBUFF_TMP(&buffer[i], 1));
p[(i * 3) + 2] = '-';
}