adding radius message handling functions

This commit is contained in:
hyung-hwan 2021-08-12 09:32:24 +00:00
parent 7963f140b5
commit 09f9dd8f51
69 changed files with 1716 additions and 164 deletions

View File

@ -44,6 +44,7 @@ include_HEADERS = \
hio-path.h \
hio-pipe.h \
hio-pro.h \
hio-rad.h \
hio-sck.h \
hio-skad.h \
hio-thr.h \
@ -74,12 +75,14 @@ libhio_la_SOURCES = \
json.c \
hio-prv.h \
hio.c \
md5.c \
nwif.c \
opt.c \
opt-imp.h \
path.c \
pipe.c \
pro.c \
rad-msg.c \
sck.c \
skad.c \
sys.c \

View File

@ -150,10 +150,11 @@ libhio_la_DEPENDENCIES = $(am__DEPENDENCIES_2) $(am__DEPENDENCIES_1) \
am__libhio_la_SOURCES_DIST = chr.c dns.c dns-cli.c ecs.c ecs-imp.h \
err.c fmt.c fmt-imp.h htb.c htrd.c htre.c http.c http-cgi.c \
http-fil.c http-prv.h http-svr.c http-thr.c http-txt.c json.c \
hio-prv.h hio.c nwif.c opt.c opt-imp.h path.c pipe.c pro.c \
sck.c skad.c sys.c sys-ass.c sys-err.c sys-log.c sys-mux.c \
sys-prv.h sys-tim.c thr.c uch-case.h uch-prop.h tmr.c utf8.c \
utl.c utl-siph.c utl-str.c mar.c mar-cli.c
hio-prv.h hio.c md5.c nwif.c opt.c opt-imp.h path.c pipe.c \
pro.c rad-msg.c sck.c skad.c sys.c sys-ass.c sys-err.c \
sys-log.c sys-mux.c sys-prv.h sys-tim.c thr.c uch-case.h \
uch-prop.h tmr.c utf8.c utl.c utl-siph.c utl-str.c mar.c \
mar-cli.c
@ENABLE_MARIADB_TRUE@am__objects_1 = libhio_la-mar.lo \
@ENABLE_MARIADB_TRUE@ libhio_la-mar-cli.lo
am_libhio_la_OBJECTS = libhio_la-chr.lo libhio_la-dns.lo \
@ -162,13 +163,14 @@ am_libhio_la_OBJECTS = libhio_la-chr.lo libhio_la-dns.lo \
libhio_la-htre.lo libhio_la-http.lo libhio_la-http-cgi.lo \
libhio_la-http-fil.lo libhio_la-http-svr.lo \
libhio_la-http-thr.lo libhio_la-http-txt.lo libhio_la-json.lo \
libhio_la-hio.lo libhio_la-nwif.lo libhio_la-opt.lo \
libhio_la-path.lo libhio_la-pipe.lo libhio_la-pro.lo \
libhio_la-sck.lo libhio_la-skad.lo libhio_la-sys.lo \
libhio_la-sys-ass.lo libhio_la-sys-err.lo libhio_la-sys-log.lo \
libhio_la-sys-mux.lo libhio_la-sys-tim.lo libhio_la-thr.lo \
libhio_la-tmr.lo libhio_la-utf8.lo libhio_la-utl.lo \
libhio_la-utl-siph.lo libhio_la-utl-str.lo $(am__objects_1)
libhio_la-hio.lo libhio_la-md5.lo libhio_la-nwif.lo \
libhio_la-opt.lo libhio_la-path.lo libhio_la-pipe.lo \
libhio_la-pro.lo libhio_la-rad-msg.lo libhio_la-sck.lo \
libhio_la-skad.lo libhio_la-sys.lo libhio_la-sys-ass.lo \
libhio_la-sys-err.lo libhio_la-sys-log.lo libhio_la-sys-mux.lo \
libhio_la-sys-tim.lo libhio_la-thr.lo libhio_la-tmr.lo \
libhio_la-utf8.lo libhio_la-utl.lo libhio_la-utl-siph.lo \
libhio_la-utl-str.lo $(am__objects_1)
libhio_la_OBJECTS = $(am_libhio_la_OBJECTS)
AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
@ -205,9 +207,11 @@ am__depfiles_remade = ./$(DEPDIR)/libhio_la-chr.Plo \
./$(DEPDIR)/libhio_la-http-txt.Plo \
./$(DEPDIR)/libhio_la-http.Plo ./$(DEPDIR)/libhio_la-json.Plo \
./$(DEPDIR)/libhio_la-mar-cli.Plo \
./$(DEPDIR)/libhio_la-mar.Plo ./$(DEPDIR)/libhio_la-nwif.Plo \
./$(DEPDIR)/libhio_la-opt.Plo ./$(DEPDIR)/libhio_la-path.Plo \
./$(DEPDIR)/libhio_la-pipe.Plo ./$(DEPDIR)/libhio_la-pro.Plo \
./$(DEPDIR)/libhio_la-mar.Plo ./$(DEPDIR)/libhio_la-md5.Plo \
./$(DEPDIR)/libhio_la-nwif.Plo ./$(DEPDIR)/libhio_la-opt.Plo \
./$(DEPDIR)/libhio_la-path.Plo ./$(DEPDIR)/libhio_la-pipe.Plo \
./$(DEPDIR)/libhio_la-pro.Plo \
./$(DEPDIR)/libhio_la-rad-msg.Plo \
./$(DEPDIR)/libhio_la-sck.Plo ./$(DEPDIR)/libhio_la-skad.Plo \
./$(DEPDIR)/libhio_la-sys-ass.Plo \
./$(DEPDIR)/libhio_la-sys-err.Plo \
@ -248,8 +252,8 @@ am__can_run_installinfo = \
am__include_HEADERS_DIST = hio-cfg.h hio-chr.h hio-cmn.h hio-dns.h \
hio-ecs.h hio-fmt.h hio-htb.h hio-htrd.h hio-htre.h hio-http.h \
hio-json.h hio-nwif.h hio-opt.h hio-pac1.h hio-path.h \
hio-pipe.h hio-pro.h hio-sck.h hio-skad.h hio-thr.h hio-upac.h \
hio-utl.h hio.h hio-mar.h
hio-pipe.h hio-pro.h hio-rad.h hio-sck.h hio-skad.h hio-thr.h \
hio-upac.h hio-utl.h hio.h hio-mar.h
HEADERS = $(include_HEADERS)
am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) \
hio-cfg.h.in
@ -439,16 +443,16 @@ LIBADD_LIB_COMMON = $(LIBM)
include_HEADERS = hio-cfg.h hio-chr.h hio-cmn.h hio-dns.h hio-ecs.h \
hio-fmt.h hio-htb.h hio-htrd.h hio-htre.h hio-http.h \
hio-json.h hio-nwif.h hio-opt.h hio-pac1.h hio-path.h \
hio-pipe.h hio-pro.h hio-sck.h hio-skad.h hio-thr.h hio-upac.h \
hio-utl.h hio.h $(am__append_1)
hio-pipe.h hio-pro.h hio-rad.h hio-sck.h hio-skad.h hio-thr.h \
hio-upac.h hio-utl.h hio.h $(am__append_1)
lib_LTLIBRARIES = libhio.la
libhio_la_SOURCES = chr.c dns.c dns-cli.c ecs.c ecs-imp.h err.c fmt.c \
fmt-imp.h htb.c htrd.c htre.c http.c http-cgi.c http-fil.c \
http-prv.h http-svr.c http-thr.c http-txt.c json.c hio-prv.h \
hio.c nwif.c opt.c opt-imp.h path.c pipe.c pro.c sck.c skad.c \
sys.c sys-ass.c sys-err.c sys-log.c sys-mux.c sys-prv.h \
sys-tim.c thr.c uch-case.h uch-prop.h tmr.c utf8.c utl.c \
utl-siph.c utl-str.c $(am__append_2)
hio.c md5.c nwif.c opt.c opt-imp.h path.c pipe.c pro.c \
rad-msg.c sck.c skad.c sys.c sys-ass.c sys-err.c sys-log.c \
sys-mux.c sys-prv.h sys-tim.c thr.c uch-case.h uch-prop.h \
tmr.c utf8.c utl.c utl-siph.c utl-str.c $(am__append_2)
libhio_la_CPPFLAGS = $(CPPFLAGS_LIB_COMMON)
libhio_la_CFLAGS = $(CFLAGS_LIB_COMMON) $(am__append_3)
libhio_la_LDFLAGS = $(LDFLAGS_LIB_COMMON) $(am__append_4)
@ -567,11 +571,13 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhio_la-json.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhio_la-mar-cli.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhio_la-mar.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhio_la-md5.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhio_la-nwif.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhio_la-opt.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhio_la-path.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhio_la-pipe.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhio_la-pro.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhio_la-rad-msg.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhio_la-sck.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhio_la-skad.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhio_la-sys-ass.Plo@am__quote@ # am--include-marker
@ -736,6 +742,13 @@ libhio_la-hio.lo: hio.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhio_la_CPPFLAGS) $(CPPFLAGS) $(libhio_la_CFLAGS) $(CFLAGS) -c -o libhio_la-hio.lo `test -f 'hio.c' || echo '$(srcdir)/'`hio.c
libhio_la-md5.lo: md5.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhio_la_CPPFLAGS) $(CPPFLAGS) $(libhio_la_CFLAGS) $(CFLAGS) -MT libhio_la-md5.lo -MD -MP -MF $(DEPDIR)/libhio_la-md5.Tpo -c -o libhio_la-md5.lo `test -f 'md5.c' || echo '$(srcdir)/'`md5.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhio_la-md5.Tpo $(DEPDIR)/libhio_la-md5.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='md5.c' object='libhio_la-md5.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhio_la_CPPFLAGS) $(CPPFLAGS) $(libhio_la_CFLAGS) $(CFLAGS) -c -o libhio_la-md5.lo `test -f 'md5.c' || echo '$(srcdir)/'`md5.c
libhio_la-nwif.lo: nwif.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhio_la_CPPFLAGS) $(CPPFLAGS) $(libhio_la_CFLAGS) $(CFLAGS) -MT libhio_la-nwif.lo -MD -MP -MF $(DEPDIR)/libhio_la-nwif.Tpo -c -o libhio_la-nwif.lo `test -f 'nwif.c' || echo '$(srcdir)/'`nwif.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhio_la-nwif.Tpo $(DEPDIR)/libhio_la-nwif.Plo
@ -771,6 +784,13 @@ libhio_la-pro.lo: pro.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhio_la_CPPFLAGS) $(CPPFLAGS) $(libhio_la_CFLAGS) $(CFLAGS) -c -o libhio_la-pro.lo `test -f 'pro.c' || echo '$(srcdir)/'`pro.c
libhio_la-rad-msg.lo: rad-msg.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhio_la_CPPFLAGS) $(CPPFLAGS) $(libhio_la_CFLAGS) $(CFLAGS) -MT libhio_la-rad-msg.lo -MD -MP -MF $(DEPDIR)/libhio_la-rad-msg.Tpo -c -o libhio_la-rad-msg.lo `test -f 'rad-msg.c' || echo '$(srcdir)/'`rad-msg.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhio_la-rad-msg.Tpo $(DEPDIR)/libhio_la-rad-msg.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='rad-msg.c' object='libhio_la-rad-msg.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhio_la_CPPFLAGS) $(CPPFLAGS) $(libhio_la_CFLAGS) $(CFLAGS) -c -o libhio_la-rad-msg.lo `test -f 'rad-msg.c' || echo '$(srcdir)/'`rad-msg.c
libhio_la-sck.lo: sck.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhio_la_CPPFLAGS) $(CPPFLAGS) $(libhio_la_CFLAGS) $(CFLAGS) -MT libhio_la-sck.lo -MD -MP -MF $(DEPDIR)/libhio_la-sck.Tpo -c -o libhio_la-sck.lo `test -f 'sck.c' || echo '$(srcdir)/'`sck.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhio_la-sck.Tpo $(DEPDIR)/libhio_la-sck.Plo
@ -1057,11 +1077,13 @@ distclean: distclean-am
-rm -f ./$(DEPDIR)/libhio_la-json.Plo
-rm -f ./$(DEPDIR)/libhio_la-mar-cli.Plo
-rm -f ./$(DEPDIR)/libhio_la-mar.Plo
-rm -f ./$(DEPDIR)/libhio_la-md5.Plo
-rm -f ./$(DEPDIR)/libhio_la-nwif.Plo
-rm -f ./$(DEPDIR)/libhio_la-opt.Plo
-rm -f ./$(DEPDIR)/libhio_la-path.Plo
-rm -f ./$(DEPDIR)/libhio_la-pipe.Plo
-rm -f ./$(DEPDIR)/libhio_la-pro.Plo
-rm -f ./$(DEPDIR)/libhio_la-rad-msg.Plo
-rm -f ./$(DEPDIR)/libhio_la-sck.Plo
-rm -f ./$(DEPDIR)/libhio_la-skad.Plo
-rm -f ./$(DEPDIR)/libhio_la-sys-ass.Plo
@ -1141,11 +1163,13 @@ maintainer-clean: maintainer-clean-am
-rm -f ./$(DEPDIR)/libhio_la-json.Plo
-rm -f ./$(DEPDIR)/libhio_la-mar-cli.Plo
-rm -f ./$(DEPDIR)/libhio_la-mar.Plo
-rm -f ./$(DEPDIR)/libhio_la-md5.Plo
-rm -f ./$(DEPDIR)/libhio_la-nwif.Plo
-rm -f ./$(DEPDIR)/libhio_la-opt.Plo
-rm -f ./$(DEPDIR)/libhio_la-path.Plo
-rm -f ./$(DEPDIR)/libhio_la-pipe.Plo
-rm -f ./$(DEPDIR)/libhio_la-pro.Plo
-rm -f ./$(DEPDIR)/libhio_la-rad-msg.Plo
-rm -f ./$(DEPDIR)/libhio_la-sck.Plo
-rm -f ./$(DEPDIR)/libhio_la-skad.Plo
-rm -f ./$(DEPDIR)/libhio_la-sys-ass.Plo

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -203,7 +201,7 @@ typedef void (*hio_svc_marc_on_result_t) (
/* -------------------------------------------------------------- */
#ifdef __cplusplus
#if defined(__cplusplus)
extern "C" {
#endif
@ -294,7 +292,7 @@ HIO_EXPORT hio_oow_t hio_svc_marc_escapebchars (
hio_bch_t* buf
);
#ifdef __cplusplus
#if defined(__cplusplus)
}
#endif

71
hio/lib/hio-md5.h Normal file
View File

@ -0,0 +1,71 @@
/*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _HIO_MD5_H_
#define _HIO_MD5_H_
#include <hio.h>
#define HIO_MD5_DIGEST_LEN (16)
#define HIO_MD5_BLOCK_LEN (64)
struct hio_md5_t
{
hio_uint32_t count[2];
hio_uint32_t state[4];
hio_uint8_t buffer[HIO_MD5_BLOCK_LEN];
};
typedef struct hio_md5_t hio_md5_t;
#ifdef __cplusplus
extern "C" {
#endif
HIO_EXPORT void hio_md5_initialize (
hio_md5_t* md5
);
HIO_EXPORT void hio_md5_update (
hio_md5_t* md5,
const void* data,
hio_uint32_t len
);
HIO_EXPORT void hio_md5_updatex (
hio_md5_t* md5,
const void* data,
hio_oow_t len
);
HIO_EXPORT hio_oow_t hio_md5_digest (
hio_md5_t* md5,
void* digest,
hio_oow_t size
);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -92,7 +90,7 @@ enum hio_dev_pipe_ioctl_cmd_t
};
typedef enum hio_dev_pipe_ioctl_cmd_t hio_dev_pipe_ioctl_cmd_t;
#ifdef __cplusplus
#if defined(__cplusplus)
extern "C" {
#endif
@ -153,7 +151,7 @@ HIO_EXPORT int hio_dev_pipe_close (
hio_dev_pipe_sid_t sid
);
#ifdef __cplusplus
#if defined(__cplusplus)
}
#endif

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -138,7 +136,7 @@ enum hio_dev_pro_ioctl_cmd_t
};
typedef enum hio_dev_pro_ioctl_cmd_t hio_dev_pro_ioctl_cmd_t;
#ifdef __cplusplus
#if defined(__cplusplus)
extern "C" {
#endif
@ -205,7 +203,7 @@ HIO_EXPORT int hio_dev_pro_killchild (
hio_dev_pro_t* pro
);
#ifdef __cplusplus
#if defined(__cplusplus)
}
#endif

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -108,7 +106,7 @@
(hio)->_shuterr = __shuterr; \
} while(0)
#ifdef __cplusplus
#if defined(__cplusplus)
extern "C" {
#endif
@ -218,7 +216,7 @@ void hio_sys_getrealtime (
hio_ntime_t* now
);
#ifdef __cplusplus
#if defined(__cplusplus)
}
#endif

453
hio/lib/hio-rad.h Normal file
View File

@ -0,0 +1,453 @@
/*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _HIO_RAD_H_
#define _HIO_RAD_H_
#include <hio.h>
#include <hio-skad.h>
/* -----------------------------------------------------------
* RARIUS MESSAGE DEFINITIONS
* ----------------------------------------------------------- */
#define HIO_RAD_PACKET_MAX (65535)
/* radius code */
enum hio_rad_code_t
{
HIO_RAD_ACCESS_REQUEST = 1,
HIO_RAD_ACCESS_ACCEPT = 2,
HIO_RAD_ACCESS_REJECT = 3,
HIO_RAD_ACCOUNTING_REQUEST = 4,
HIO_RAD_ACCOUNTING_RESPONSE = 5,
HIO_RAD_ACCESS_CHALLENGE = 6,
HIO_RAD_DISCONNECT_REQUEST = 40,
HIO_RAD_DISCONNECT_ACK = 41,
HIO_RAD_DISCONNECT_NAK = 42,
HIO_RAD_COA_REQUEST = 43,
HIO_RAD_COA_ACK = 44,
HIO_RAD_COA_NAK = 45,
HIO_RAD_ACCOUNTING_ERROR = 255 /* this is not a real radius code */
};
typedef enum hio_rad_code_t hio_rad_code_t;
#define HIO_RAD_MAX_AUTHENTICATOR_LEN 16
#define HIO_RAD_MAX_ATTR_VALUE_LEN (HIO_TYPE_MAX(hio_uint8_t) - HIO_SIZEOF(hio_rad_attr_hdr_t))
#define HIO_RAD_MAX_XATTR_VALUE_LEN (HIO_TYPE_MAX(hio_uint8_t) - HIO_SIZEOF(hio_rad_xattr_hdr_t))
#define HIO_RAD_MAX_LXATTR_VALUE_LEN (HIO_TYPE_MAX(hio_uint8_t) - HIO_SIZEOF(hio_rad_lxattr_hdr_t))
#define HIO_RAD_MAX_VSATTR_VALUE_LEN (HIO_TYPE_MAX(hio_uint8_t) - HIO_SIZEOF(hio_rad_vsattr_hdr_t))
#define HIO_RAD_MAX_XVSATTR_VALUE_LEN (HIO_TYPE_MAX(hio_uint8_t) - HIO_SIZEOF(hio_rad_xvsattr_hdr_t))
#define HIO_RAD_MAX_LXVSATTR_VALUE_LEN (HIO_TYPE_MAX(hio_uint8_t) - HIO_SIZEOF(hio_rad_lxvsattr_hdr_t))
typedef struct hio_rad_hdr_t hio_rad_hdr_t;
typedef struct hio_rad_attr_hdr_t hio_rad_attr_hdr_t;
typedef struct hio_rad_xattr_hdr_t hio_rad_xattr_hdr_t;
typedef struct hio_rad_lxattr_hdr_t hio_rad_lxattr_hdr_t;
typedef struct hio_rad_vsattr_hdr_t hio_rad_vsattr_hdr_t;
typedef struct hio_rad_xvsattr_hdr_t hio_rad_xvsattr_hdr_t;
typedef struct hio_rad_lxvsattr_hdr_t hio_rad_lxvsattr_hdr_t; /* evs */
typedef struct hio_rad_attr_uint32_t hio_rad_attr_uint32_t;
#if (HIO_SIZEOF_UINT64_T > 0)
typedef struct hio_rad_attr_uint64_t hio_rad_attr_uint64_t;
#endif
#include <hio-pac1.h>
struct hio_rad_hdr_t
{
hio_uint8_t code; /* hio_rad_code_t */
hio_uint8_t id;
hio_uint16_t length;
hio_uint8_t authenticator[HIO_RAD_MAX_AUTHENTICATOR_LEN]; /* authenticator */
};
struct hio_rad_attr_hdr_t
{
hio_uint8_t type; /* hio_rad_attr_type_t */
hio_uint8_t length;
};
struct hio_rad_xattr_hdr_t
{
hio_uint8_t type; /* hio_rad_attr_type_t - one of 241-244 */
hio_uint8_t length;
hio_uint8_t xtype; /* extended type */
};
struct hio_rad_lxattr_hdr_t
{
hio_uint8_t type; /* hio_rad_attr_type_t - 245 or 256*/
hio_uint8_t length;
hio_uint8_t xtype; /* extended type */
hio_uint8_t xflags; /* bit 7: continuation, bit 6-0: reserved. */
};
struct hio_rad_vsattr_hdr_t
{
hio_uint8_t type; /* type - 26 */
hio_uint8_t length; /* length */
hio_uint32_t vendor; /* in network-byte order */
/* followed by a standard attribute */
hio_rad_attr_hdr_t vs;
};
struct hio_rad_xvsattr_hdr_t
{
hio_uint8_t type; /* one of 241-244 */
hio_uint8_t length;
hio_uint8_t xtype; /* extended type. 26 for evs(extended vendor specific) attribute */
hio_uint32_t vendor; /* in network-byte order */
/* followed by a standard attribute */
hio_rad_attr_hdr_t xvs;
};
struct hio_rad_lxvsattr_hdr_t
{
hio_uint8_t type; /* 245, 246*/
hio_uint8_t length;
hio_uint8_t xtype; /* extended type. 26 for evs(extended vendor specific) attribute */
hio_uint32_t vendor; /* in network-byte order */
/* followed by an extended attribute */
struct
{
hio_uint8_t type;
hio_uint8_t flags; /* bit 7: continuation, bit 6-0: reserved. */
hio_uint8_t length;
} lxvs;
};
struct hio_rad_attr_uint32_t
{
hio_rad_attr_hdr_t hdr;
hio_uint32_t val;
};
#if (HIO_SIZEOF_UINT64_T > 0)
struct hio_rad_attr_uint64_t
{
hio_rad_attr_hdr_t hdr;
hio_uint64_t val;
};
#endif
#include <hio-upac.h>
typedef int (*hio_rad_attr_walker_t) (
const hio_rad_hdr_t* hdr,
hio_uint32_t vendor, /* in host-byte order */
const hio_rad_attr_hdr_t* attr,
void* ctx
);
enum hio_rad_attr_type_t
{
HIO_RAD_ATTR_USER_NAME = 1, /* string */
HIO_RAD_ATTR_USER_PASSWORD = 2, /* string encrypted */
HIO_RAD_ATTR_NAS_IP_ADDRESS = 4, /* ipaddr */
HIO_RAD_ATTR_NAS_PORT = 5, /* integer */
HIO_RAD_ATTR_SERVICE_TYPE = 6, /* integer */
HIO_RAD_ATTR_FRAMED_IP_ADDRESS = 8, /* ipaddr */
HIO_RAD_ATTR_REPLY_MESSAGE = 18, /* string */
HIO_RAD_ATTR_CLASS = 25, /* octets */
HIO_RAD_ATTR_VENDOR_SPECIFIC = 26, /* octets */
HIO_RAD_ATTR_SESSION_TIMEOUT = 27, /* integer */
HIO_RAD_ATTR_IDLE_TIMEOUT = 28, /* integer */
HIO_RAD_ATTR_TERMINATION_ACTION = 29, /* integer. 0:default, 1:radius-request */
HIO_RAD_ATTR_CALLING_STATION_ID = 31, /* string */
HIO_RAD_ATTR_NAS_IDENTIFIER = 32, /* string */
HIO_RAD_ATTR_ACCT_STATUS_TYPE = 40, /* integer */
HIO_RAD_ATTR_ACCT_INPUT_OCTETS = 42, /* integer */
HIO_RAD_ATTR_ACCT_OUTPUT_OCTETS = 43, /* integer */
HIO_RAD_ATTR_ACCT_SESSION_ID = 44, /* string */
HIO_RAD_ATTR_ACCT_SESSION_TIME = 46, /* integer */
HIO_RAD_ATTR_ACCT_TERMINATE_CAUSE = 49, /* integer */
HIO_RAD_ATTR_ACCT_INPUT_GIGAWORDS = 52, /* integer */
HIO_RAD_ATTR_ACCT_OUTPUT_GIGAWORDS = 53, /* integer */
HIO_RAD_ATTR_EVENT_TIMESTAMP = 55, /* integer */
HIO_RAD_ATTR_NAS_PORT_TYPE = 61, /* integer */
HIO_RAD_ATTR_ACCT_INTERIM_INTERVAL = 85, /* integer */
HIO_RAD_ATTR_NAS_PORT_ID = 87, /* string */
HIO_RAD_ATTR_FRAMED_IPV6_PREFIX = 97, /* ipv6prefix */
HIO_RAD_ATTR_EXTENDED_1 = 241,
HIO_RAD_ATTR_EXTENDED_2 = 242,
HIO_RAD_ATTR_EXTENDED_3 = 243,
HIO_RAD_ATTR_EXTENDED_4 = 244,
HIO_RAD_ATTR_EXTENDED_5 = 245, /* long extended */
HIO_RAD_ATTR_EXTENDED_6 = 246, /* long extended */
};
#define HIO_RAD_ATTR_IS_SHORT_EXTENDED(attrtype) ((attrtype) >= HIO_RAD_ATTR_EXTENDED_1 && (attrtype) <= HIO_RAD_ATTR_EXTENDED_4)
#define HIO_RAD_ATTR_IS_LONG_EXTENDED(attrtype) ((attrtype) >= HIO_RAD_ATTR_EXTENDED_5 && (attrtype) <= HIO_RAD_ATTR_EXTENDED_6)
#define HIO_RAD_ATTR_IS_EXTENDED(attrtype) ((attrtype) >= HIO_RAD_ATTR_EXTENDED_1 && (attrtype) <= HIO_RAD_ATTR_EXTENDED_6)
enum hio_rad_attr_acct_status_type_t
{
HIO_RAD_ATTR_ACCT_STATUS_TYPE_START = 1, /* accounting start */
HIO_RAD_ATTR_ACCT_STATUS_TYPE_STOP = 2, /* accounting stop */
HIO_RAD_ATTR_ACCT_STATUS_TYPE_UPDATE = 3, /* interim update */
HIO_RAD_ATTR_ACCT_STATUS_TYPE_ON = 7, /* accounting on */
HIO_RAD_ATTR_ACCT_STATUS_TYPE_OFF = 8, /* accounting off */
HIO_RAD_ATTR_ACCT_STATUS_TYPE_FAILED = 15
};
enum hio_rad_attr_acct_terminate_cause_t
{
HIO_RAD_ATTR_ACCT_TERMINATE_CAUSE_USER_REQUEST = 1,
HIO_RAD_ATTR_ACCT_TERMINATE_CAUSE_LOST_CARRIER = 2,
HIO_RAD_ATTR_ACCT_TERMINATE_CAUSE_LOST_SERVICE = 3,
HIO_RAD_ATTR_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT = 4,
HIO_RAD_ATTR_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT = 5,
HIO_RAD_ATTR_ACCT_TERMINATE_CAUSE_ADMIN_RESET = 6,
HIO_RAD_ATTR_ACCT_TERMINATE_CAUSE_ADMIN_REBOOT = 7,
HIO_RAD_ATTR_ACCT_TERMINATE_CAUSE_PORT_ERROR = 8,
HIO_RAD_ATTR_ACCT_TERMINATE_CAUSE_NAS_ERROR = 9,
HIO_RAD_ATTR_ACCT_TERMINATE_CAUSE_NAS_REQUEST = 10,
HIO_RAD_ATTR_ACCT_TERMINATE_CAUSE_NAS_REBOOT = 11,
HIO_RAD_ATTR_ACCT_TERMINATE_CAUSE_PORT_UNNEEDED = 12,
HIO_RAD_ATTR_ACCT_TERMINATE_CAUSE_PORT_PREEMPTED = 13,
HIO_RAD_ATTR_ACCT_TERMINATE_CAUSE_PORT_SUSPENDED = 14,
HIO_RAD_ATTR_ACCT_TERMINATE_CAUSE_SERVICE_UNAVAILABLE = 15,
HIO_RAD_ATTR_ACCT_TERMINATE_CAUSE_CALLBACK = 16,
HIO_RAD_ATTR_ACCT_TERMINATE_CAUSE_USER_ERROR = 17,
HIO_RAD_ATTR_ACCT_TERMINATE_CAUSE_HOST_REQUEST = 18
};
enum hio_rad_attr_nas_port_type_t
{
HIO_RAD_ATTR_NAS_PORT_TYPE_ASYNC = 0,
HIO_RAD_ATTR_NAS_PORT_TYPE_SYNC = 1,
HIO_RAD_ATTR_NAS_PORT_TYPE_ISDN = 2,
HIO_RAD_ATTR_NAS_PORT_TYPE_ISDN_V120 = 3,
HIO_RAD_ATTR_NAS_PORT_TYPE_ISDN_V110 = 4,
HIO_RAD_ATTR_NAS_PORT_TYPE_VIRTUAL = 5
/* TODO: more types */
};
#if defined(__cplusplus)
extern "C" {
#endif
/* -----------------------------------------------------------
* RARIUS MESSAGE FUNCTIONS
* ----------------------------------------------------------- */
HIO_EXPORT void hio_rad_initialize (
hio_rad_hdr_t* hdr,
hio_rad_code_t code,
hio_uint8_t id
);
HIO_EXPORT hio_rad_attr_hdr_t* hio_rad_find_attribute (
hio_rad_hdr_t* hdr,
hio_uint8_t attrtype,
int index
);
HIO_EXPORT hio_rad_vsattr_hdr_t* hio_rad_find_vsattr (
hio_rad_hdr_t* hdr,
hio_uint32_t vendor,
hio_uint8_t attrtype,
int index
);
HIO_EXPORT hio_rad_xvsattr_hdr_t* hio_rad_find_extended_vsattr (
hio_rad_hdr_t* hdr,
hio_uint32_t vendor,
hio_uint8_t xtype,
hio_uint8_t attrtype,
int index
);
HIO_EXPORT hio_rad_attr_hdr_t* hio_rad_find_vendor_specific_attribute (
hio_rad_hdr_t* hdr,
hio_uint32_t vendor,
hio_uint8_t id,
int index
);
HIO_EXPORT int hio_rad_walk_attributes (
const hio_rad_hdr_t* hdr,
hio_rad_attr_walker_t walker,
void* ctx
);
HIO_EXPORT int hio_rad_insert_attribute (
hio_rad_hdr_t* auth,
int max,
hio_uint8_t id,
const void* ptr,
hio_uint8_t len
);
HIO_EXPORT int hio_rad_insert_vendor_specific_attribute (
hio_rad_hdr_t* auth,
int max,
hio_uint32_t vendor,
hio_uint8_t attrtype,
const void* ptr,
hio_uint8_t len
);
HIO_EXPORT int hio_rad_insert_extended_vendor_specific_attribute (
hio_rad_hdr_t* auth,
int max,
hio_uint32_t vendor,
hio_uint8_t xtype, /* HIO_RAD_ATTR_EXTENDED_X */
hio_uint8_t attrtype,
const void* ptr,
hio_uint8_t len,
hio_uint8_t lxflags
);
HIO_EXPORT int hio_rad_delete_attribute (
hio_rad_hdr_t* auth,
hio_uint8_t attrtype,
int index
);
HIO_EXPORT int hio_rad_delete_vendor_specific_attribute (
hio_rad_hdr_t* auth,
hio_uint32_t vendor,
hio_uint8_t attrtype,
int index
);
HIO_EXPORT int hio_rad_delete_extended_vendor_specific_attribute (
hio_rad_hdr_t* auth,
hio_uint32_t vendor,
hio_uint8_t xtype, /* HIO_RAD_ATTR_EXTENDED_X */
hio_uint8_t attrtype,
int index
);
HIO_EXPORT int hio_rad_insert_attribute_with_bcstr (
hio_rad_hdr_t* auth,
int max,
hio_uint32_t vendor, /* in host-byte order */
hio_uint8_t id,
const hio_bch_t* value
);
HIO_EXPORT int hio_rad_insert_attribute_ucstr (
hio_rad_hdr_t* auth,
int max,
hio_uint32_t vendor, /* in host-byte order */
hio_uint8_t id,
const hio_uch_t* value
);
HIO_EXPORT int hio_rad_insert_attribute_with_bchars (
hio_rad_hdr_t* auth,
int max,
hio_uint32_t vendor, /* in host-byte order */
hio_uint8_t id,
const hio_bch_t* value,
hio_uint8_t length
);
HIO_EXPORT int hio_rad_insert_attribute_with_uchars (
hio_rad_hdr_t* auth,
int max,
hio_uint32_t vendor, /* in host-byte order */
hio_uint8_t id,
const hio_uch_t* value,
hio_uint8_t length
);
HIO_EXPORT int hio_rad_insert_uint32_attribute (
hio_rad_hdr_t* auth,
int max,
hio_uint32_t vendor, /* in host-byte order */
hio_uint8_t id,
hio_uint32_t value /* in host-byte order */
);
HIO_EXPORT int hio_rad_insert_ipv6prefix_attribute (
hio_rad_hdr_t* auth,
int max,
hio_uint32_t vendor, /* in host-byte order */
hio_uint8_t id,
hio_uint8_t prefix_bits,
const hio_ip6ad_t* value
);
HIO_EXPORT int hio_rad_insert_giga_attribute (
hio_rad_hdr_t* auth,
int max,
hio_uint32_t vendor,
int low_id,
int high_id,
hio_uint64_t value
);
HIO_EXPORT int hio_rad_set_user_password (
hio_rad_hdr_t* auth,
int max,
const hio_bch_t* password,
const hio_bch_t* secret
);
HIO_EXPORT void hio_rad_fill_authenticator (
hio_rad_hdr_t* auth
);
HIO_EXPORT void hio_rad_copy_authenticator (
hio_rad_hdr_t* dst,
const hio_rad_hdr_t* src
);
HIO_EXPORT int hio_rad_set_authenticator (
hio_rad_hdr_t* req,
const hio_bch_t* secret
);
/*
* verify an accounting request.
* the authenticator of an access request is filled randomly.
* so this function doesn't apply
*/
HIO_EXPORT int hio_rad_verify_request (
hio_rad_hdr_t* req,
const hio_bch_t* secret
);
HIO_EXPORT int hio_rad_verify_response (
hio_rad_hdr_t* res,
const hio_rad_hdr_t* req,
const hio_bch_t* secret
);
#if defined(__cplusplus)
}
#endif
#endif

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -445,7 +443,7 @@ struct hio_dev_sck_qxmsg_t
typedef struct hio_dev_sck_qxmsg_t hio_dev_sck_qxmsg_t;
#ifdef __cplusplus
#if defined(__cplusplus)
extern "C" {
#endif
@ -614,7 +612,7 @@ HIO_EXPORT hio_uint16_t hio_checksum_ip (
hio_oow_t len
);
#ifdef __cplusplus
#if defined(__cplusplus)
}
#endif

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -111,7 +109,7 @@ enum hio_dev_thr_ioctl_cmd_t
};
typedef enum hio_dev_thr_ioctl_cmd_t hio_dev_thr_ioctl_cmd_t;
#ifdef __cplusplus
#if defined(__cplusplus)
extern "C" {
#endif
@ -177,7 +175,7 @@ void hio_dev_thr_haltslave (
hio_dev_thr_sid_t sid
);
#ifdef __cplusplus
#if defined(__cplusplus)
}
#endif

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -241,7 +239,7 @@ enum hio_trim_oochars_flag_t
#define HIO_TRIM_BCHARS_RIGHT HIO_TRIM_OOCHARS_RIGHT
};
#ifdef __cplusplus
#if defined(__cplusplus)
extern "C" {
#endif
@ -1077,7 +1075,7 @@ HIO_EXPORT void hio_sip_hash_24 (
hio_uint8_t out[8]
);
#ifdef __cplusplus
#if defined(__cplusplus)
}
#endif

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -764,7 +762,7 @@ struct hio_t
/* ========================================================================= */
#ifdef __cplusplus
#if defined(__cplusplus)
extern "C" {
#endif
@ -1422,7 +1420,7 @@ HIO_EXPORT hio_oow_t hio_dev_cap_to_bcstr (
hio_oow_t bsz
);
#ifdef __cplusplus
#if defined(__cplusplus)
}
#endif

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2018 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

307
hio/lib/md5.c Normal file
View File

@ -0,0 +1,307 @@
/*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <hio-md5.h>
#include "hio-prv.h"
/*
Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
rights reserved.
License to copy and use this software is granted provided that it
is identified as the "RSA Data Security, Inc. MD5 Message-Digest
Algorithm" in all material mentioning or referencing this software
or this function.
License is also granted to make and use derivative works provided
that such works are identified as "derived from the RSA Data
Security, Inc. MD5 Message-Digest Algorithm" in all material
mentioning or referencing the derived work.
RSA Data Security, Inc. makes no representations concerning either
the merchantability of this software or the suitability of this
software for any particular purpose. It is provided "as is"
without express or implied warranty of any kind.
These notices must be retained in any copies of any part of this
documentation and/or software.
*/
#define S11 7
#define S12 12
#define S13 17
#define S14 22
#define S21 5
#define S22 9
#define S23 14
#define S24 20
#define S31 4
#define S32 11
#define S33 16
#define S34 23
#define S41 6
#define S42 10
#define S43 15
#define S44 21
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
#define H(x, y, z) ((x) ^ (y) ^ (z))
#define I(x, y, z) ((y) ^ ((x) | (~z)))
/* ROTATE_LEFT rotates x left n bits. */
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
#define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (hio_uint32_t)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (hio_uint32_t)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (hio_uint32_t)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (hio_uint32_t)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
static hio_uint8_t padding[64] = {
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
static void __transform (hio_uint32_t state[4], hio_uint8_t block[64]);
static void __encode (hio_uint8_t* output, hio_uint32_t* input, hio_oow_t len);
static void __decode (hio_uint32_t* output, hio_uint8_t* input, hio_oow_t len);
void hio_md5_initialize (hio_md5_t* md5)
{
md5->count[0] = 0;
md5->count[1] = 0;
md5->state[0] = 0x67452301;
md5->state[1] = 0xEFCDAB89;
md5->state[2] = 0x98BADCFE;
md5->state[3] = 0x10325476;
}
void hio_md5_update (hio_md5_t* md5, const void* data, hio_uint32_t len)
{
hio_uint8_t* input = (hio_uint8_t*)data;
hio_uint32_t index, part_len, i;
/* compute number of bytes mod 64 */
index = (hio_uint32_t)((md5->count[0] >> 3) & 0x3F);
/* update number of bits */
md5->count[0] += ((hio_uint32_t)len << 3);
if (md5->count[0] < ((hio_uint32_t)len << 3)) md5->count[1]++;
md5->count[1] += (hio_uint32_t)len >> 29;
part_len = 64 - index;
/* transform as many times as possible */
if (len >= part_len)
{
HIO_MEMCPY (&md5->buffer[index], input, part_len);
__transform (md5->state, md5->buffer);
for (i = part_len; i + 63 < len; i += 64)
__transform (md5->state, &input[i]);
index = 0;
}
else i = 0;
/* buffer remaining input */
HIO_MEMCPY (&md5->buffer[index], &input[i], len - i);
}
void hio_md5_updatex (hio_md5_t* md5, const void* data, hio_oow_t len)
{
/* if len is greater than the max value of hio_uint32_t,
it splits the data to multiple calls to hio_md5_update */
const hio_uint8_t* input = (hio_uint8_t*)data;
while (len > HIO_TYPE_MAX(hio_uint32_t))
{
hio_md5_update (md5, input, HIO_TYPE_MAX(hio_uint32_t));
input += HIO_TYPE_MAX(hio_uint32_t);
len -= HIO_TYPE_MAX(hio_uint32_t);
}
hio_md5_update (md5, input, len);
}
hio_oow_t hio_md5_digest (hio_md5_t* md5, void* digest, hio_oow_t size)
{
hio_uint8_t bits[8];
hio_uint32_t index, pad_len;
hio_uint8_t digbuf[HIO_MD5_DIGEST_LEN];
/* save number of bits */
__encode (bits, md5->count, 8);
/* pad out to 56 mod 64 */
index = (hio_uint32_t)((md5->count[0] >> 3) & 0x3F);
pad_len = (index < 56)? (56 - index): (120 - index);
hio_md5_update (md5, padding, pad_len);
/* append length (before padding) */
hio_md5_update (md5, bits, 8);
/* store state in digest */
__encode (digbuf, md5->state, HIO_COUNTOF(digbuf));
hio_md5_initialize (md5);
if (size > HIO_COUNTOF(digbuf)) size = HIO_COUNTOF(digbuf);
HIO_MEMCPY (digest, digbuf, size);
return size;
}
static void __transform (hio_uint32_t state[4], hio_uint8_t block[64])
{
hio_uint32_t a, b, c, d, x[16];
a = state[0];
b = state[1];
c = state[2];
d = state[3];
__decode (x, block, 64);
/* Round 1 */
FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
/* Round 2 */
GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
/* Round 3 */
HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
/* Round 4 */
II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
state[0] += a;
state[1] += b;
state[2] += c;
state[3] += d;
}
static void __encode (hio_uint8_t* output, hio_uint32_t* input, hio_oow_t len)
{
hio_oow_t i, j;
for (i = 0, j = 0; j < len; i++, j += 4)
{
output[j + 0] = (hio_uint8_t)((input[i] >> 0) & 0xFF);
output[j + 1] = (hio_uint8_t)((input[i] >> 8) & 0xFF);
output[j + 2] = (hio_uint8_t)((input[i] >> 16) & 0xFF);
output[j + 3] = (hio_uint8_t)((input[i] >> 24) & 0xFF);
}
}
static void __decode (hio_uint32_t* output, hio_uint8_t* input, hio_oow_t len)
{
hio_oow_t i, j;
for (i = 0, j = 0; j < len; i++, j += 4)
{
output[i] = input[j] | (input[j + 1] << 8) | (input[j + 2] << 16) | (input[j + 3] << 24);
}
}

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

820
hio/lib/rad-msg.c Normal file
View File

@ -0,0 +1,820 @@
/*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <hio-rad.h>
#include <hio-md5.h>
#include "hio-prv.h"
#include <fcntl.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>
void hio_rad_initialize (hio_rad_hdr_t* hdr, hio_rad_code_t code, hio_uint8_t id)
{
HIO_MEMSET (hdr, 0, sizeof(*hdr));
hdr->code = code;
hdr->id = id;
hdr->length = hio_hton16(sizeof(*hdr));
}
static HIO_INLINE void xor (void* p, void* q, int length)
{
int i;
hio_uint8_t* pp = (hio_uint8_t*)p;
hio_uint8_t* qq = (hio_uint8_t*)q;
for (i = 0; i < length; i++) *(pp++) ^= *(qq++);
}
static void fill_authenticator_randomly (void* authenticator, int length)
{
hio_uint8_t* v = (hio_uint8_t*)authenticator;
int total = 0;
#if defined(__linux)
int fd;
fd = open("/dev/urandom", O_RDONLY, 0); /* Linux: get *real* random numbers */
if (fd >= 0)
{
while (total < length)
{
int bytes = read(fd, &v[total], length - total);
if (bytes <= 0) break;
total += bytes;
}
close (fd);
}
#endif
if (total < length)
{
struct timeval now;
unsigned int seed;
gettimeofday (&now, HIO_NULL);
seed = getpid() + now.tv_sec + now.tv_usec;
srandom (seed);
while (total < length)
{
seed = random();
v[total] = seed % HIO_TYPE_MAX(hio_uint8_t);
total++;
}
}
}
static hio_rad_attr_hdr_t* find_attribute (hio_rad_attr_hdr_t* attr, int* len, hio_uint8_t attrtype)
{
int rem = *len;
while (rem >= HIO_SIZEOF(*attr))
{
/* sanity checks */
if (rem < attr->length) return HIO_NULL;
if (attr->length < HIO_SIZEOF(*attr))
{
/* attribute length cannot be less than the header size.
* the packet could be corrupted... */
return HIO_NULL;
}
rem -= attr->length;
if (attr->type == attrtype)
{
*len = rem; /* remaining length */
return attr;
}
attr = (hio_rad_attr_hdr_t*)((hio_uint8_t*)attr + attr->length);
}
return HIO_NULL;
}
static hio_rad_attr_hdr_t* find_extended_attribute (hio_rad_attr_hdr_t* attr, int* len, hio_uint8_t xtype, hio_uint8_t attrtype)
{
int rem = *len;
/* xtype must be one of the followings:
* HIO_RAD_ATTR_EXTENDED_1
* HIO_RAD_ATTR_EXTENDED_2
* HIO_RAD_ATTR_EXTENDED_3
* HIO_RAD_ATTR_EXTENDED_4
* HIO_RAD_ATTR_EXTENDED_5
* HIO_RAD_ATTR_EXTENDED_6
*/
while (rem >= HIO_SIZEOF(*attr))
{
/* sanity checks */
if (rem < attr->length) return HIO_NULL;
/* attribute length cannot be less than the header size.
* the packet could be corrupted... */
if (attr->length < HIO_SIZEOF(*attr)) goto oops;
rem -= attr->length;
if (attr->type == xtype)
{
hio_uint8_t xattrtype;
if (HIO_RAD_ATTR_IS_LONG_EXTENDED(xtype))
{
hio_rad_lxattr_hdr_t* lxattr;
lxattr = (hio_rad_lxattr_hdr_t*)attr;
if (lxattr->length < HIO_SIZEOF(*lxattr)) goto oops;
xattrtype = lxattr->xtype;
}
else
{
hio_rad_xattr_hdr_t* xattr;
xattr = (hio_rad_xattr_hdr_t*)attr;
if (xattr->length < HIO_SIZEOF(*xattr)) goto oops;
xattrtype = xattr->xtype;
}
if (xattrtype == attrtype)
{
*len = rem;
return attr;
}
}
attr = (hio_rad_attr_hdr_t*)((hio_uint8_t*)attr + attr->length);
}
oops:
return HIO_NULL;
}
hio_rad_attr_hdr_t* hio_rad_find_attribute (hio_rad_hdr_t* hdr, hio_uint8_t attrtype, int index)
{
hio_rad_attr_hdr_t *attr = (hio_rad_attr_hdr_t*)(hdr+1);
if (hio_ntoh16(hdr->length) >= HIO_SIZEOF(*hdr))
{
int len = hio_ntoh16(hdr->length) - HIO_SIZEOF(*hdr);
attr = find_attribute(attr, &len, attrtype);
while (attr)
{
if (index <= 0) return attr;
index--;
attr = find_attribute((hio_rad_attr_hdr_t*)((hio_uint8_t*)attr+attr->length), &len, attrtype);
}
}
return HIO_NULL;
}
hio_rad_attr_hdr_t* hio_rad_find_extended_attribute (hio_rad_hdr_t* hdr, hio_uint8_t xtype, hio_uint8_t attrtype, int index)
{
hio_rad_attr_hdr_t *attr = (hio_rad_attr_hdr_t*)(hdr + 1);
if (HIO_RAD_ATTR_IS_EXTENDED(xtype) && hio_ntoh16(hdr->length) >= HIO_SIZEOF(*hdr))
{
int len = hio_ntoh16(hdr->length) - HIO_SIZEOF(*hdr);
attr = find_extended_attribute(attr, &len, xtype, attrtype);
while (attr)
{
if (index <= 0) return attr;
index--;
attr = find_extended_attribute((hio_rad_attr_hdr_t*)((hio_uint8_t*)attr + attr->length), &len, xtype, attrtype);
}
}
return HIO_NULL;
}
hio_rad_vsattr_hdr_t* hio_rad_find_vsattr (hio_rad_hdr_t* hdr, hio_uint32_t vendor, hio_uint8_t attrtype, int index)
{
hio_rad_attr_hdr_t *attr = (hio_rad_attr_hdr_t*)(hdr+1);
if (hio_ntoh16(hdr->length) >= HIO_SIZEOF(*hdr))
{
int len = hio_ntoh16(hdr->length) - HIO_SIZEOF(*hdr);
attr = find_attribute(attr, &len, HIO_RAD_ATTR_VENDOR_SPECIFIC);
while (attr)
{
hio_rad_vsattr_hdr_t* vsattr;
if (attr->length >= HIO_SIZEOF(*vsattr)) /* sanity check */
{
vsattr = (hio_rad_vsattr_hdr_t*)attr;
if (hio_ntoh32(vsattr->vendor) == vendor && vsattr->vs.type == attrtype)
{
int val_len;
val_len = (int)vsattr->length - HIO_SIZEOF(*vsattr);
if ((int)vsattr->vs.length == val_len + HIO_SIZEOF(vsattr->vs))
{
if (index <= 0) return vsattr;
index--;
}
}
}
attr = find_attribute((hio_rad_attr_hdr_t*)((hio_uint8_t*)attr + attr->length), &len, HIO_RAD_ATTR_VENDOR_SPECIFIC);
}
}
return HIO_NULL;
}
hio_rad_xvsattr_hdr_t* hio_rad_find_extended_vsattr (hio_rad_hdr_t* hdr, hio_uint32_t vendor, hio_uint8_t xtype, hio_uint8_t attrtype, int index)
{
hio_rad_attr_hdr_t *attr = (hio_rad_attr_hdr_t*)(hdr+1);
if (HIO_RAD_ATTR_IS_EXTENDED(xtype) && hio_ntoh16(hdr->length) >= HIO_SIZEOF(*hdr))
{
int len = hio_ntoh16(hdr->length) - HIO_SIZEOF(*hdr);
attr = find_extended_attribute(attr, &len, xtype, HIO_RAD_ATTR_VENDOR_SPECIFIC);
while (attr)
{
if (HIO_RAD_ATTR_IS_LONG_EXTENDED(xtype))
{
hio_rad_lxvsattr_hdr_t* lxvsattr;
if (attr->length >= HIO_SIZEOF(*lxvsattr)) /* sanity check */
{
lxvsattr = (hio_rad_lxvsattr_hdr_t*)attr;
if (hio_ntoh32(lxvsattr->vendor) == vendor && lxvsattr->lxvs.type == attrtype)
{
int val_len;
val_len = (int)lxvsattr->length - HIO_SIZEOF(*lxvsattr);
if ((int)lxvsattr->lxvs.length == val_len + HIO_SIZEOF(lxvsattr->lxvs))
{
/* the caller must check if the extended type is long.
* if long, it must cast back to hio_rad_lxvsattr_hdr_t* */
if (index <= 0) return (hio_rad_xvsattr_hdr_t*)lxvsattr;
index--;
}
}
}
}
else
{
hio_rad_xvsattr_hdr_t* xvsattr;
if (attr->length >= HIO_SIZEOF(*xvsattr)) /* sanity check */
{
xvsattr = (hio_rad_xvsattr_hdr_t*)attr;
if (hio_ntoh32(xvsattr->vendor) == vendor && xvsattr->xvs.type == attrtype)
{
int val_len;
val_len = (int)xvsattr->length - HIO_SIZEOF(*xvsattr);
if ((int)xvsattr->xvs.length == val_len + HIO_SIZEOF(xvsattr->xvs))
{
if (index <= 0) return xvsattr;
index--;
}
}
}
}
attr = find_extended_attribute((hio_rad_attr_hdr_t*)((hio_uint8_t*)attr + attr->length), &len, xtype, HIO_RAD_ATTR_VENDOR_SPECIFIC);
}
}
return HIO_NULL;
}
hio_rad_attr_hdr_t* hio_rad_find_vendor_specific_attribute (hio_rad_hdr_t* hdr, hio_uint32_t vendor, hio_uint8_t attrtype, int index)
{
hio_rad_vsattr_hdr_t* vsattr;
vsattr = hio_rad_find_vsattr(hdr, vendor, attrtype, index);
return vsattr? &vsattr->vs: HIO_NULL;
}
int hio_rad_walk_attributes (const hio_rad_hdr_t* hdr, hio_rad_attr_walker_t walker, void* ctx)
{
int totlen, rem;
hio_rad_attr_hdr_t* attr;
totlen = hio_ntoh16(hdr->length);
if (totlen < HIO_SIZEOF(*hdr)) return -1;
rem = totlen - HIO_SIZEOF(*hdr);
attr = (hio_rad_attr_hdr_t*)(hdr + 1);
while (rem >= HIO_SIZEOF(*attr))
{
/* sanity checks */
if (rem < attr->length) return -1;
if (attr->length < HIO_SIZEOF(*attr))
{
/* attribute length cannot be less than the header size.
* the packet could be corrupted... */
return -1;
}
rem -= attr->length;
if (attr->type == HIO_RAD_ATTR_VENDOR_SPECIFIC)
{
hio_rad_vsattr_hdr_t* vsattr;
int val_len;
if (attr->length < HIO_SIZEOF(*vsattr)) return -1;
vsattr = (hio_rad_vsattr_hdr_t*)attr;
val_len = (int)vsattr->length - HIO_SIZEOF(*vsattr);
if ((int)vsattr->vs.length != val_len + HIO_SIZEOF(vsattr->vs)) return -1;
/* if this vendor happens to be 0, walker can't tell
* if it is vendor specific or not because 0 is passed in
* for non-VSAs. but i don't care. in reality,
* 0 is reserved in IANA enterpirse number assignments.
* (http://www.iana.org/assignments/enterprise-numbers) */
if (walker(hdr, hio_ntoh32(vsattr->vendor), &vsattr->vs, ctx) <= -1) return -1;
}
else
{
if (walker(hdr, 0, attr, ctx) <= -1) return -1;
}
attr = (hio_rad_attr_hdr_t*)((hio_uint8_t*) attr + attr->length);
}
return 0;
}
int hio_rad_insert_attribute (
hio_rad_hdr_t* auth, int max,
hio_uint8_t id, const void* ptr, hio_uint8_t len)
{
hio_rad_attr_hdr_t* attr;
int auth_len = hio_ntoh16(auth->length);
int new_auth_len;
/*if (len > HIO_RAD_MAX_ATTR_VALUE_LEN) return -1;*/
if (len > HIO_RAD_MAX_ATTR_VALUE_LEN) len = HIO_RAD_MAX_ATTR_VALUE_LEN;
new_auth_len = auth_len + len + HIO_SIZEOF(*attr);
if (new_auth_len > max) return -1;
attr = (hio_rad_attr_hdr_t*)((hio_uint8_t*)auth + auth_len);
attr->type = id;
attr->length = new_auth_len - auth_len;
HIO_MEMCPY (attr + 1, ptr, len);
auth->length = hio_hton16(new_auth_len);
return 0;
}
int hio_rad_insert_vendor_specific_attribute (
hio_rad_hdr_t* auth, int max,
hio_uint32_t vendor, hio_uint8_t attrtype, const void* ptr, hio_uint8_t len)
{
hio_rad_vsattr_hdr_t* vsattr;
int auth_len = hio_ntoh16(auth->length);
int new_auth_len;
/*if (len > HIO_RAD_MAX_VSATTR_VALUE_LEN) return -1;*/
if (len > HIO_RAD_MAX_VSATTR_VALUE_LEN) len = HIO_RAD_MAX_VSATTR_VALUE_LEN;
new_auth_len = auth_len + HIO_SIZEOF(*vsattr) + len;
if (new_auth_len > max) return -1;
vsattr = (hio_rad_vsattr_hdr_t*)((hio_uint8_t*)auth + auth_len);
vsattr->type = HIO_RAD_ATTR_VENDOR_SPECIFIC;
vsattr->length = new_auth_len - auth_len;
vsattr->vendor = hio_hton32(vendor);
vsattr->vs.type = attrtype;
vsattr->vs.length = HIO_SIZEOF(vsattr->vs) + len;
HIO_MEMCPY (vsattr + 1, ptr, len);
auth->length = hio_hton16(new_auth_len);
return 0;
}
static int delete_attribute (hio_rad_hdr_t* auth, hio_rad_attr_hdr_t* attr)
{
hio_uint16_t auth_len;
hio_uint16_t tmp_len;
auth_len = hio_ntoh16(auth->length);
tmp_len = ((hio_uint8_t*)attr - (hio_uint8_t*)auth) + attr->length;
if (tmp_len > auth_len) return -1; /* can this happen? */
HIO_MEMCPY (attr, (hio_uint8_t*)attr + attr->length, auth_len - tmp_len);
auth_len -= attr->length;
auth->length = hio_hton16(auth_len);
return 0;
}
int hio_rad_delete_attribute (hio_rad_hdr_t* auth, hio_uint8_t attrtype, int index)
{
hio_rad_attr_hdr_t* attr;
attr = hio_rad_find_attribute(auth, attrtype, index);
if (!attr) return 0; /* not found */
return (delete_attribute(auth, attr) <= -1)? -1: 1;
}
int hio_rad_delete_vendor_specific_attribute (
hio_rad_hdr_t* auth, hio_uint32_t vendor, hio_uint8_t attrtype, int index)
{
hio_rad_vsattr_hdr_t* vsattr;
vsattr = hio_rad_find_vsattr(auth, vendor, attrtype, 0);
if (!vsattr) return 0; /* not found */
return (delete_attribute(auth, (hio_rad_attr_hdr_t*)vsattr) <= -1)? -1: 1;
}
int hio_rad_delete_extended_vendor_specific_attribute (
hio_rad_hdr_t* auth, hio_uint32_t vendor, hio_uint8_t xtype, hio_uint8_t attrtype, int index)
{
hio_rad_xvsattr_hdr_t* xvsattr;
xvsattr = hio_rad_find_extended_vsattr(auth, vendor, xtype, attrtype, 0);
if (!xvsattr) return 0; /* not found */
return (delete_attribute(auth, (hio_rad_attr_hdr_t*)xvsattr) <= -1)? -1: 1;
}
int hio_rad_insert_attribute_with_bcstr (
hio_rad_hdr_t* auth, int max, hio_uint32_t vendor,
hio_uint8_t id, const hio_bch_t* value)
{
return (vendor == 0)?
hio_rad_insert_attribute(auth, max, id, value, hio_count_bcstr(value)):
hio_rad_insert_vendor_specific_attribute(auth, max, vendor, id, value, hio_count_bcstr(value));
}
int hio_rad_insert_attribute_with_ucstr (
hio_rad_hdr_t* auth, int max, hio_uint32_t vendor,
hio_uint8_t id, const hio_uch_t* value)
{
int n;
hio_oow_t bcslen, ucslen;
hio_bch_t bcsval[HIO_RAD_MAX_ATTR_VALUE_LEN + 1];
bcslen = HIO_COUNTOF(bcsval);
if (hio_conv_ucstr_to_utf8(value, &ucslen, bcsval, &bcslen) <= -1) return -1;
n = (vendor == 0)?
hio_rad_insert_attribute(auth, max, id, bcsval, bcslen):
hio_rad_insert_vendor_specific_attribute(auth, max, vendor, id, bcsval, bcslen);
return n;
}
int hio_rad_insert_attribute_with_bchars (
hio_rad_hdr_t* auth, int max, hio_uint32_t vendor,
hio_uint8_t id, const hio_bch_t* value, hio_uint8_t length)
{
return (vendor == 0)?
hio_rad_insert_attribute(auth, max, id, value, length):
hio_rad_insert_vendor_specific_attribute(auth, max, vendor, id, value, length);
}
int hio_rad_insert_attribute_with_uchars (
hio_rad_hdr_t* auth, int max, hio_uint32_t vendor,
hio_uint8_t id, const hio_uch_t* value, hio_uint8_t length)
{
int n;
hio_oow_t bcslen, ucslen;
hio_bch_t bcsval[HIO_RAD_MAX_ATTR_VALUE_LEN];
ucslen = length;
bcslen = HIO_COUNTOF(bcsval);
if (hio_conv_uchars_to_utf8(value, &ucslen, bcsval, &bcslen) <= -1) return -1;
n = (vendor == 0)?
hio_rad_insert_attribute(auth, max, id, bcsval, bcslen):
hio_rad_insert_vendor_specific_attribute(auth, max, vendor, id, bcsval, bcslen);
return n;
}
int hio_rad_insert_uint32_attribute (
hio_rad_hdr_t* auth, int max, hio_uint32_t vendor, hio_uint8_t id, hio_uint32_t value)
{
hio_uint32_t val = hio_hton32(value);
return (vendor == 0)?
hio_rad_insert_attribute(auth, max, id, &val, HIO_SIZEOF(val)):
hio_rad_insert_vendor_specific_attribute(auth, max, vendor, id, &val, HIO_SIZEOF(val));
}
int hio_rad_insert_ipv6prefix_attribute (
hio_rad_hdr_t* auth, int max, hio_uint32_t vendor, hio_uint8_t id,
hio_uint8_t prefix_bits, const hio_ip6ad_t* value)
{
struct ipv6prefix_t
{
hio_uint8_t reserved;
hio_uint8_t bits;
hio_ip6ad_t value;
} __attribute__((__packed__));
struct ipv6prefix_t ipv6prefix;
hio_uint8_t i, j;
if (prefix_bits > 128) prefix_bits = 128;
HIO_MEMSET (&ipv6prefix, 0, sizeof(ipv6prefix));
ipv6prefix.bits = prefix_bits;
for (i = 0, j = 0; i < prefix_bits; i += 8, j++)
{
hio_uint8_t bits = prefix_bits - i;
if (bits >= 8)
{
ipv6prefix.value.v[j] = value->v[j];
}
else
{
/*
1 -> 10000000
2 -> 11000000
3 -> 11100000
4 -> 11110000
5 -> 11111000
6 -> 11111100
7 -> 11111110
*/
ipv6prefix.value.v[j] = value->v[j] & (0xFF << (8 - bits));
}
}
return (vendor == 0)?
hio_rad_insert_attribute(auth, max, id, &ipv6prefix, j + 2):
hio_rad_insert_vendor_specific_attribute(auth, max, vendor, id, &ipv6prefix, j + 2);
}
int hio_rad_insert_giga_attribute (
hio_rad_hdr_t* auth, int max, hio_uint32_t vendor, int low_id, int high_id, hio_uint64_t value)
{
hio_uint32_t low;
low = value & HIO_TYPE_MAX(hio_uint32_t);
low = hio_hton32(low);
if (vendor == 0)
{
if (hio_rad_insert_attribute(auth, max, low_id, &low, HIO_SIZEOF(low)) <= -1) return -1;
if (value > HIO_TYPE_MAX(hio_uint32_t))
{
hio_uint32_t high;
high = value >> (HIO_SIZEOF(hio_uint32_t) * 8);
high = hio_hton32(high);
if (hio_rad_insert_attribute(auth, max, high_id, &high, HIO_SIZEOF(high)) <= -1) return -1;
}
}
else
{
if (hio_rad_insert_vendor_specific_attribute(auth, max, vendor, low_id, &low, HIO_SIZEOF(low)) <= -1) return -1;
if (value > HIO_TYPE_MAX(hio_uint32_t))
{
hio_uint32_t high;
high = value >> (HIO_SIZEOF(hio_uint32_t) * 8);
high = hio_hton32(high);
if (hio_rad_insert_vendor_specific_attribute(auth, max, vendor, high_id, &high, HIO_SIZEOF(high)) <= -1) return -1;
}
}
return 0;
}
int hio_rad_insert_extended_vendor_specific_attribute (
hio_rad_hdr_t* auth, int max, hio_uint32_t vendor, hio_uint8_t xtype,
hio_uint8_t attrtype, const void* ptr, hio_uint8_t len, hio_uint8_t lxflags)
{
/* RFC6929 */
hio_rad_xvsattr_hdr_t* xvsattr;
int auth_len = hio_ntoh16(auth->length);
int new_auth_len, maxvallen, hdrlen;
if (HIO_RAD_ATTR_IS_SHORT_EXTENDED(xtype))
{
maxvallen = HIO_RAD_MAX_XVSATTR_VALUE_LEN;
hdrlen = HIO_SIZEOF(hio_rad_xvsattr_hdr_t);
}
else if (HIO_RAD_ATTR_IS_LONG_EXTENDED(xtype))
{
maxvallen = HIO_RAD_MAX_LXVSATTR_VALUE_LEN;
hdrlen = HIO_SIZEOF(hio_rad_lxvsattr_hdr_t);
}
else return -1;
/*if (len > maxvallen) return -1;*/
if (len > maxvallen) len = HIO_RAD_MAX_XVSATTR_VALUE_LEN;
new_auth_len = auth_len + hdrlen + len;
if (new_auth_len > max) return -1;
xvsattr = (hio_rad_xvsattr_hdr_t*)((hio_uint8_t*)auth + auth_len);
xvsattr->type = xtype;
xvsattr->length = new_auth_len - auth_len;
xvsattr->xtype = HIO_RAD_ATTR_VENDOR_SPECIFIC;
xvsattr->vendor = hio_hton32(vendor);
if (HIO_RAD_ATTR_IS_LONG_EXTENDED(xtype))
{
/* this function is still low-level. it doesn't handle continuation of big data */
hio_rad_lxvsattr_hdr_t* lxvsattr;
lxvsattr = (hio_rad_lxvsattr_hdr_t*)xvsattr;
lxvsattr->lxvs.type = attrtype;
lxvsattr->lxvs.flags = lxflags;
lxvsattr->lxvs.length = len + HIO_SIZEOF(lxvsattr->lxvs);
HIO_MEMCPY (lxvsattr + 1, ptr, len);
}
else
{
xvsattr->xvs.type = attrtype;
xvsattr->xvs.length = len + HIO_SIZEOF(xvsattr->xvs);
HIO_MEMCPY (xvsattr + 1, ptr, len);
}
auth->length = hio_hton16(new_auth_len);
return 0;
}
#define PASS_BLKSIZE HIO_RAD_MAX_AUTHENTICATOR_LEN
#define ALIGN(x,factor) ((((x) + (factor) - 1) / (factor)) * (factor))
int hio_rad_set_user_password (hio_rad_hdr_t* auth, int max, const hio_bch_t* password, const hio_bch_t* secret)
{
hio_md5_t md5;
hio_uint8_t hashed[HIO_RAD_MAX_ATTR_VALUE_LEN]; /* can't be longer than this */
hio_uint8_t tmp[PASS_BLKSIZE];
int i, pwlen, padlen;
/*HIO_ASSERT (HIO_SIZEOF(tmp) >= HIO_MD5_DIGEST_LEN);*/
pwlen = hio_count_bcstr(password);
/* calculate padlen to be the multiples of 16.
* 0 is forced to 16. */
padlen = (pwlen <= 0)? PASS_BLKSIZE: ALIGN(pwlen,PASS_BLKSIZE);
/* keep the padded length limited within the maximum attribute length */
if (padlen > HIO_RAD_MAX_ATTR_VALUE_LEN)
{
padlen = HIO_RAD_MAX_ATTR_VALUE_LEN;
padlen = ALIGN(padlen,PASS_BLKSIZE);
if (padlen > HIO_RAD_MAX_ATTR_VALUE_LEN) padlen -= PASS_BLKSIZE;
/* also limit the original length */
if (pwlen > padlen) pwlen = padlen;
}
HIO_MEMSET (hashed, 0, padlen);
HIO_MEMCPY (hashed, password, pwlen);
/*
* c1 = p1 XOR MD5(secret + authenticator)
* c2 = p2 XOR MD5(secret + c1)
* ...
* cn = pn XOR MD5(secret + cn-1)
*/
hio_md5_initialize (&md5);
hio_md5_update (&md5, secret, hio_count_bcstr(secret));
hio_md5_update (&md5, auth->authenticator, HIO_SIZEOF(auth->authenticator));
hio_md5_digest (&md5, tmp, HIO_SIZEOF(tmp));
xor (&hashed[0], tmp, HIO_SIZEOF(tmp));
for (i = 1; i < (padlen >> 4); i++)
{
hio_md5_initialize (&md5);
hio_md5_update (&md5, secret, hio_count_bcstr(secret));
hio_md5_update (&md5, &hashed[(i-1) * PASS_BLKSIZE], PASS_BLKSIZE);
hio_md5_digest (&md5, tmp, HIO_SIZEOF(tmp));
xor (&hashed[i * PASS_BLKSIZE], tmp, HIO_SIZEOF(tmp));
}
/* ok if not found or deleted. but not ok if an error occurred */
while (1)
{
int n;
n = hio_rad_delete_attribute(auth, HIO_RAD_ATTR_USER_PASSWORD, 0);
if (n <= -1) goto oops;
if (n == 0) break;
}
if (hio_rad_insert_attribute(auth, max, HIO_RAD_ATTR_USER_PASSWORD, hashed, padlen) <= -1) goto oops;
return 0;
oops:
return -1;
}
void hio_rad_fill_authenticator (hio_rad_hdr_t* auth)
{
fill_authenticator_randomly (auth->authenticator, HIO_SIZEOF(auth->authenticator));
}
void hio_rad_copy_authenticator (hio_rad_hdr_t* dst, const hio_rad_hdr_t* src)
{
HIO_MEMCPY (dst->authenticator, src->authenticator, HIO_SIZEOF(dst->authenticator));
}
int hio_rad_set_authenticator (hio_rad_hdr_t* req, const hio_bch_t* secret)
{
hio_md5_t md5;
/* this assumes that req->authentcator at this point
* is filled with zeros. so make sure that it contains zeros
* before you call this function */
hio_md5_initialize (&md5);
hio_md5_update (&md5, req, hio_ntoh16(req->length));
if (*secret) hio_md5_update (&md5, secret, hio_count_bcstr(secret));
hio_md5_digest (&md5, req->authenticator, HIO_SIZEOF(req->authenticator));
return 0;
}
int hio_rad_verify_request (hio_rad_hdr_t* req, const hio_bch_t* secret)
{
hio_md5_t md5;
hio_uint8_t orgauth[HIO_RAD_MAX_AUTHENTICATOR_LEN];
int ret;
HIO_MEMCPY (orgauth, req->authenticator, HIO_SIZEOF(req->authenticator));
HIO_MEMSET (req->authenticator, 0, HIO_SIZEOF(req->authenticator));
hio_md5_initialize (&md5);
hio_md5_update (&md5, req, hio_ntoh16(req->length));
if (*secret) hio_md5_update (&md5, secret, hio_count_bcstr(secret));
hio_md5_digest (&md5, req->authenticator, HIO_SIZEOF(req->authenticator));
ret = (HIO_MEMCMP (req->authenticator, orgauth, HIO_SIZEOF(req->authenticator)) == 0)? 1: 0;
HIO_MEMCPY (req->authenticator, orgauth, HIO_SIZEOF(req->authenticator));
return ret;
}
int hio_rad_verify_response (hio_rad_hdr_t* res, const hio_rad_hdr_t* req, const hio_bch_t* secret)
{
hio_md5_t md5;
hio_uint8_t calculated[HIO_RAD_MAX_AUTHENTICATOR_LEN];
hio_uint8_t reply[HIO_RAD_MAX_AUTHENTICATOR_LEN];
/*HIO_ASSERT (HIO_SIZEOF(req->authenticator) == HIO_RAD_MAX_AUTHENTICATOR_LEN);
HIO_ASSERT (HIO_SIZEOF(res->authenticator) == HIO_RAD_MAX_AUTHENTICATOR_LEN);*/
/*
* We could dispense with the HIO_MEMCPY, and do MD5's of the packet
* + authenticator piece by piece. This is easier understand,
* and maybe faster.
*/
HIO_MEMCPY(reply, res->authenticator, HIO_SIZEOF(res->authenticator)); /* save the reply */
HIO_MEMCPY(res->authenticator, req->authenticator, HIO_SIZEOF(req->authenticator)); /* sent authenticator */
/* MD5(response packet header + authenticator + response packet data + secret) */
hio_md5_initialize (&md5);
hio_md5_update (&md5, res, hio_ntoh16(res->length));
/*
* This next bit is necessary because of a bug in the original Livingston
* RADIUS server. The authentication authenticator is *supposed* to be
* MD5'd with the old password (as the secret) for password changes.
* However, the old password isn't used. The "authentication" authenticator
* for the server reply packet is simply the MD5 of the reply packet.
* Odd, the code is 99% there, but the old password is never copied
* to the secret!
*/
if (*secret) hio_md5_update (&md5, secret, hio_count_bcstr(secret));
hio_md5_digest (&md5, calculated, HIO_SIZEOF(calculated));
/* Did he use the same random authenticator + shared secret? */
return (HIO_MEMCMP(calculated, reply, HIO_SIZEOF(reply)) != 0)? 0: 1;
}

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without