]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
New plugin architecture code - first draft.
authorZhanna Tsitkov <tsitkova@mit.edu>
Wed, 14 Apr 2010 18:43:37 +0000 (18:43 +0000)
committerZhanna Tsitkov <tsitkova@mit.edu>
Wed, 14 Apr 2010 18:43:37 +0000 (18:43 +0000)
This design provides the following advantages:

1. Simple and clear additions of new plugin APIs and new implementations of the existing plugins
2. Handle both static and dynamic plugins
3. Handle two types of plugins: Listener and Service
4. Uniform way to supply parameters for plugin configuration
5. Possible versioning of configuration
6. Potentially, configuration file  may contain hash values for the library validity verification
7. Tables of functions are created during make.

It was tested by implementing yarrow as PRNG plugin. (There is also a bogus plugin_prng_os implementation which uses system rand calls just for the demonstration purpose)
t_prng and all other tests in crypto_tests work (need to run "make check" from crypto_tests dir)
This particular version suggests using plugin configuration file in yaml format. It can be alternated by hardcoded or any other configuration.

git-svn-id: svn://anonsvn.mit.edu/krb5/branches/plugins@23902 dc483132-0cff-0310-8789-dd5450dbe970

59 files changed:
src/Makefile.in
src/config/pre.in
src/configure.in
src/include/k5-int.h
src/lib/crypto/Makefile.in
src/lib/crypto/builtin/Makefile.in
src/lib/crypto/crypto_tests/Makefile.in
src/lib/crypto/crypto_tests/plugin_conf.yml [new file with mode: 0755]
src/lib/crypto/crypto_tests/t_cksum.c
src/lib/crypto/crypto_tests/t_encrypt.c
src/lib/crypto/crypto_tests/t_prng.c
src/lib/crypto/crypto_tests/t_short.c
src/lib/crypto/krb/Makefile.in
src/lib/crypto/krb/deps
src/lib/crypto/krb/prng.c
src/lib/crypto/krb/yarrow/Makefile.in [deleted file]
src/lib/crypto/libk5crypto.exports
src/plugin_core/Makefile.in [new file with mode: 0644]
src/plugin_core/deps [new file with mode: 0644]
src/plugin_core/impl/Makefile.in [new file with mode: 0644]
src/plugin_core/impl/deps [new file with mode: 0644]
src/plugin_core/impl/plugin_default_factory.c [new file with mode: 0644]
src/plugin_core/impl/plugin_default_factory.h [new file with mode: 0644]
src/plugin_core/impl/plugin_default_manager.c [new file with mode: 0644]
src/plugin_core/impl/plugin_default_manager.h [new file with mode: 0644]
src/plugin_core/impl/plugin_impl.exports [new file with mode: 0644]
src/plugin_core/plugin_core.exports [new file with mode: 0644]
src/plugin_core/plugin_factory.c [new file with mode: 0644]
src/plugin_core/plugin_factory.h [new file with mode: 0644]
src/plugin_core/plugin_manager.c [new file with mode: 0644]
src/plugin_core/plugin_manager.h [new file with mode: 0644]
src/plugin_core/yaml_parser.c [new file with mode: 0644]
src/plugin_core/yaml_parser.h [new file with mode: 0644]
src/plugins/prng/Makefile.in [new file with mode: 0644]
src/plugins/prng/deps [new file with mode: 0644]
src/plugins/prng/plugin_prng.c [new file with mode: 0644]
src/plugins/prng/plugin_prng.h [new file with mode: 0644]
src/plugins/prng/plugin_prng_os/Makefile.in [new file with mode: 0644]
src/plugins/prng/plugin_prng_os/deps [new file with mode: 0644]
src/plugins/prng/plugin_prng_os/os.exports [new file with mode: 0644]
src/plugins/prng/plugin_prng_os/plugin_prng_impl.c [new file with mode: 0644]
src/plugins/prng/plugin_prng_os/plugin_prng_impl.h [new file with mode: 0644]
src/plugins/prng/plugin_yarrow/ASSUMPTIONS [moved from src/lib/crypto/krb/yarrow/ASSUMPTIONS with 100% similarity]
src/plugins/prng/plugin_yarrow/LICENSE [moved from src/lib/crypto/krb/yarrow/LICENSE with 100% similarity]
src/plugins/prng/plugin_yarrow/Makefile.in [new file with mode: 0644]
src/plugins/prng/plugin_yarrow/README [moved from src/lib/crypto/krb/yarrow/README with 100% similarity]
src/plugins/prng/plugin_yarrow/TODO [moved from src/lib/crypto/krb/yarrow/TODO with 100% similarity]
src/plugins/prng/plugin_yarrow/deps [moved from src/lib/crypto/krb/yarrow/deps with 73% similarity]
src/plugins/prng/plugin_yarrow/yarrow.c [moved from src/lib/crypto/krb/yarrow/yarrow.c with 100% similarity]
src/plugins/prng/plugin_yarrow/yarrow.h [moved from src/lib/crypto/krb/yarrow/yarrow.h with 100% similarity]
src/plugins/prng/plugin_yarrow/yarrow.man [moved from src/lib/crypto/krb/yarrow/yarrow.man with 100% similarity]
src/plugins/prng/plugin_yarrow/yarrow.pod [moved from src/lib/crypto/krb/yarrow/yarrow.pod with 100% similarity]
src/plugins/prng/plugin_yarrow/ycipher.c [moved from src/lib/crypto/krb/yarrow/ycipher.c with 100% similarity]
src/plugins/prng/plugin_yarrow/ycipher.h [moved from src/lib/crypto/krb/yarrow/ycipher.h with 100% similarity]
src/plugins/prng/plugin_yarrow/yexcep.h [moved from src/lib/crypto/krb/yarrow/yexcep.h with 100% similarity]
src/plugins/prng/plugin_yarrow/ylock.h [moved from src/lib/crypto/krb/yarrow/ylock.h with 100% similarity]
src/plugins/prng/plugin_yarrow/ystate.h [moved from src/lib/crypto/krb/yarrow/ystate.h with 100% similarity]
src/plugins/prng/plugin_yarrow/ytypes.h [moved from src/lib/crypto/krb/yarrow/ytypes.h with 100% similarity]
src/plugins/prng/prng.exports [new file with mode: 0644]

index ed0e69c14214a6ed059298f52a32f6f49a967cc1..36d15ba077754e2bbb83223c99d242b7c6bbd0cd 100644 (file)
@@ -7,7 +7,8 @@ mydir=.
 #      plugins/preauth/wpse
 #      plugins/preauth/cksum_body
 #      plugins/authdata/greet
-SUBDIRS=util include lib \
+SUBDIRS=util include plugins/prng   plugin_core  lib \
+       plugins/prng/plugin_yarrow   plugin_core/impl   \
        @ldap_plugin_dir@ \
        plugins/kdb/db2 \
        plugins/preauth/pkinit \
index 6bf9cc438ee105e9d67710e29d9aaba5106bda04..4f69cfbbb763d859f1c205f24684932fcb1d7064 100644 (file)
@@ -324,6 +324,8 @@ GSSRPC_DEPLIB       = $(TOPLIBD)/libgssrpc$(DEPLIBEXT)
 GSS_DEPLIB     = $(TOPLIBD)/libgssapi_krb5$(DEPLIBEXT)
 KRB5_DEPLIB    = $(TOPLIBD)/libkrb5$(DEPLIBEXT)
 CRYPTO_DEPLIB  = $(TOPLIBD)/libk5crypto$(DEPLIBEXT)
+PLUGIN_CORE_DEPLIB     = $(TOPLIBD)/../plugin_core/plugin_core$(DEPLIBEXT)
+PLUGIN_PRNG_DEPLIB     = $(TOPLIBD)/../plugins/prng/plugin_prng$(DEPLIBEXT)
 COM_ERR_DEPLIB = $(COM_ERR_DEPLIB-@COM_ERR_VERSION@)
 COM_ERR_DEPLIB-sys = # empty
 COM_ERR_DEPLIB-k5 = $(TOPLIBD)/libcom_err$(DEPLIBEXT)
@@ -337,7 +339,7 @@ SS_DEPLIB-k5        = $(TOPLIBD)/libss.a
 SS_DEPLIB-sys  =
 APPUTILS_DEPLIB        = $(TOPLIBD)/libapputils.a
 
-KRB5_BASE_DEPLIBS      = $(KRB5_DEPLIB) $(CRYPTO_DEPLIB) $(COM_ERR_DEPLIB) $(SUPPORT_DEPLIB)
+KRB5_BASE_DEPLIBS      = $(KRB5_DEPLIB)  $(PLUGIN_CORE_DEPLIB) $(CRYPTO_DEPLIB) $(COM_ERR_DEPLIB) $(SUPPORT_DEPLIB) $(PLUGIN_PRNG_DEPLIB)
 KDB5_DEPLIBS           = $(KDB5_DEPLIB) $(KDB5_PLUGIN_DEPLIBS)
 GSS_DEPLIBS            = $(GSS_DEPLIB)
 GSSRPC_DEPLIBS         = $(GSSRPC_DEPLIB) $(GSS_DEPLIBS)
@@ -379,7 +381,7 @@ SUPPORT_LIB                 = -l$(SUPPORT_LIBNAME)
 # HESIOD_LIBS is -lhesiod...
 HESIOD_LIBS    = @HESIOD_LIBS@
 
-KRB5_BASE_LIBS = $(KRB5_LIB) $(K5CRYPTO_LIB) $(COM_ERR_LIB) $(SUPPORT_LIB) $(GEN_LIB) $(LIBS) $(DL_LIB)
+KRB5_BASE_LIBS = $(KRB5_LIB) $(K5CRYPTO_LIB) $(COM_ERR_LIB) $(SUPPORT_LIB) $(GEN_LIB) $(LIBS) $(DL_LIB) $(PLUGIN_CORE_DEPLIB) $(PLUGIN_PRNG_DEPLIB)
 KDB5_LIBS      = $(KDB5_LIB) $(GSSRPC_LIBS)
 GSS_LIBS       = $(GSS_KRB5_LIB)
 # needs fixing if ever used on Mac OS X!
index b74fb8d1e39a1152ffc235b225b3b7f106093492..4c71d259bfd1e9104c8b8cfb86554d6fdfe3313d 100644 (file)
@@ -169,7 +169,7 @@ AC_PROG_AWK
 AC_PROG_LEX
 AC_C_CONST
 AC_HEADER_DIRENT
-AC_CHECK_FUNCS(strdup setvbuf inet_ntoa inet_aton seteuid setresuid setreuid setegid setresgid setregid setsid flock fchmod chmod strftime strptime geteuid setenv unsetenv getenv gmtime_r localtime_r bswap16 bswap64 mkstemp getusershell access getcwd srand48 srand srandom stat strchr strerror strerror_r)
+AC_CHECK_FUNCS(strdup setvbuf inet_ntoa inet_aton seteuid setresuid setreuid setegid setresgid setregid setsid flock fchmod chmod strftime strptime geteuid setenv unsetenv getenv gmtime_r localtime_r bswap16 bswap64 mkstemp getusershell lstat access getcwd srand48 srand srandom stat strchr strerror strerror_r)
 
 AC_CHECK_FUNC(mkstemp,
 [MKSTEMP_ST_OBJ=
@@ -1078,7 +1078,7 @@ V5_AC_OUTPUT_MAKEFILE(.
        lib/crypto/krb/prf lib/crypto/krb/rand2key
        lib/crypto/$CRYPTO_IMPL lib/crypto/$CRYPTO_IMPL/md4 lib/crypto/$CRYPTO_IMPL/md5
        lib/crypto/krb/old lib/crypto/krb/raw lib/crypto/$CRYPTO_IMPL/sha1
-       lib/crypto/krb/arcfour lib/crypto/krb/yarrow lib/crypto/$CRYPTO_IMPL/aes
+       lib/crypto/krb/arcfour lib/crypto/$CRYPTO_IMPL/aes
        lib/crypto/crypto_tests
 
        lib/krb5 lib/krb5/error_tables lib/krb5/asn.1 lib/krb5/ccache
@@ -1115,6 +1115,11 @@ dnl      ccapi ccapi/lib ccapi/lib/unix ccapi/server ccapi/server/unix ccapi/test
        plugins/authdata/greet_client
        plugins/authdata/greet_server
 
+       plugins/prng
+       plugin_core/impl
+       plugins/prng/plugin_yarrow
+       plugin_core
+
        clients clients/klist clients/kinit clients/kvno
        clients/kdestroy clients/kpasswd clients/ksu
 
index 8b72b06da9e41806315dfaac785700302d4438eb..df0fc2835e9cc03eacce1660ae0b03529b4799b1 100644 (file)
@@ -1424,6 +1424,14 @@ krb5_authdata_free_internal(krb5_context kcontext,
 struct _kdb5_dal_handle;        /* private, in kdb5.h */
 typedef struct _kdb5_dal_handle kdb5_dal_handle;
 struct _kdb_log_context;
+
+/* Plugin API ----  PLUGIN HANDLE */
+typedef struct _plhandle{
+        void *api;
+    struct _plhandle *next;
+} plhandle;
+
+
 struct _krb5_context {
     krb5_magic      magic;
     krb5_enctype    *in_tkt_etypes;
index 91ea0f3663155b4ccb0f7c39e1b56ff753f97bdd..495152cf96ac1617839346856f023728b0a20b50 100644 (file)
@@ -21,7 +21,7 @@ RELDIR=crypto
 STOBJLISTS=krb/crc32/OBJS.ST krb/dk/OBJS.ST @CRYPTO_IMPL@/enc_provider/OBJS.ST \
        @CRYPTO_IMPL@/hash_provider/OBJS.ST krb/checksum/OBJS.ST                \
        krb/prf/OBJS.ST krb/rand2key/OBJS.ST                                    \
-       krb/old/OBJS.ST krb/raw/OBJS.ST krb/yarrow/OBJS.ST                      \
+       krb/old/OBJS.ST krb/raw/OBJS.ST                         \
        @CRYPTO_IMPL@/md4/OBJS.ST @CRYPTO_IMPL@/md5/OBJS.ST @CRYPTO_IMPL@/sha1/OBJS.ST          \
        krb/arcfour/OBJS.ST  @CRYPTO_IMPL@/aes/OBJS.ST @CRYPTO_IMPL@/des/OBJS.ST        \
        krb/OBJS.ST  @CRYPTO_IMPL@/OBJS.ST
@@ -29,7 +29,7 @@ STOBJLISTS=krb/crc32/OBJS.ST krb/dk/OBJS.ST @CRYPTO_IMPL@/enc_provider/OBJS.ST        \
 SUBDIROBJLISTS=krb/crc32/OBJS.ST krb/dk/OBJS.ST @CRYPTO_IMPL@/enc_provider/OBJS.ST     \
        @CRYPTO_IMPL@/hash_provider/OBJS.ST krb/checksum/OBJS.ST                \
        krb/prf/OBJS.ST krb/rand2key/OBJS.ST                                    \
-       krb/old/OBJS.ST krb/raw/OBJS.ST  krb/yarrow/OBJS.ST                     \
+       krb/old/OBJS.ST krb/raw/OBJS.ST                         \
        @CRYPTO_IMPL@/md4/OBJS.ST @CRYPTO_IMPL@/md5/OBJS.ST     @CRYPTO_IMPL@/sha1/OBJS.ST              \
        krb/arcfour/OBJS.ST @CRYPTO_IMPL@/aes/OBJS.ST @CRYPTO_IMPL@/des/OBJS.ST         \
        krb/OBJS.ST @CRYPTO_IMPL@/OBJS.ST
@@ -38,7 +38,7 @@ SUBDIROBJLISTS=krb/crc32/OBJS.ST krb/dk/OBJS.ST @CRYPTO_IMPL@/enc_provider/OBJS.
 # link editor and loader support it.
 DEPLIBS=
 SHLIB_DIRS=-L$(TOPLIBD)
-SHLIB_EXPLIBS= $(SUPPORT_LIB) @CRYPTO_LIBS@ $(LIBS)
+SHLIB_EXPLIBS= $(SUPPORT_LIB) @CRYPTO_LIBS@ $(LIBS) -lyaml  $(PLUGIN_CORE_DEPLIB)  $(PLUGIN_PRNG_DEPLIB) 
 SHLIB_EXPDEPLIBS= $(SUPPORT_DEPLIB)
 SHLIB_LDFLAGS= $(LDFLAGS) @SHLIB_RPATH_DIRS@
 SHLIB_LIBDIRS= @SHLIB_LIBDIRS@
index a65f64df988504f0d06ad021c3bb528e6bdba439..be988fc1b516439e6450c5a8ed86cac75ae2ee12 100644 (file)
@@ -62,7 +62,7 @@ check-unix:: t_cf2
        diff t_cf2.output $(srcdir)/t_cf2.expected
 
 t_cf2$(EXEEXT): t_cf2.$(OBJEXT) $(SUPPORT_DEPLIB)
-       $(CC_LINK) -o $@ t_cf2.$(OBJEXT)  -lkrb5 -lk5crypto -lcom_err $(SUPPORT_LIB)
+       $(CC_LINK) -o $@ t_cf2.$(OBJEXT) -L$(BUILDTOP)/plugin_core -lkrb5 -lk5crypto -lcom_err $(SUPPORT_LIB) 
 
 clean::
        $(RM)  t_cf2 t_cf2.o  t_cf2.output
index c92cc7e8d4bbfaebcfb88ebf6fe00607df6851d4..cfda6cd142ff703fc8575e37d67c830aa78fd503 100644 (file)
@@ -3,16 +3,24 @@ BUILDTOP=$(REL)..$(S)..$(S)..
 LOCALINCLUDES = -I$(srcdir)/../krb -I$(srcdir)/../@CRYPTO_IMPL@/enc_provider           \
        -I$(srcdir)/../@CRYPTO_IMPL@/hash_provider -I$(srcdir)/../krb/keyhash_provider  \
        -I$(srcdir)/../krb/dk -I$(srcdir)/../@CRYPTO_IMPL@/                     \
-       -I$(srcdir)/../krb/yarrow       \
        -I$(srcdir)/../krb/crc32 -I$(srcdir)/../krb/old -I$(srcdir)/../krb/raw  \
        -I$(srcdir)/../@CRYPTO_IMPL@/aes -I$(srcdir)/../@CRYPTO_IMPL@/des       \
        -I$(srcdir)/../@CRYPTO_IMPL@/arcfour -I$(srcdir)/../@CRYPTO_IMPL@/sha1  \
-       -I$(srcdir)/../@CRYPTO_IMPL@/md5 -I$(srcdir)/../@CRYPTO_IMPL@/md4 
+       -I$(srcdir)/../@CRYPTO_IMPL@/md5 -I$(srcdir)/../@CRYPTO_IMPL@/md4 \
+       -I$(srcdir)/../../../plugin_core/impl  -I$(srcdir)/../../../plugins/prng \
+       -I$(srcdir)/../../../plugins/prng/plugin_yarrow -I$(srcdir)/../../../plugin_core
 RUN_SETUP = @KRB5_RUN_ENV@
 PROG_LIBPATH=-L$(TOPLIBD)
 PROG_RPATH=$(KRB5_LIBDIR)
 DEFS=
 
+PLUGINS_LIBS = \
+       ../../../plugin_core/impl/plugin_default_manager.so     \
+       ../../../plugin_core/impl/plugin_default_factory.so     \ 
+       ../../../plugins/prng/plugin_yarrow/plugin_prng_impl.so         \ 
+       ../../../plugins/prng/plugin_yarrow/yarrow.so   \ 
+       ../../../plugins/prng/plugin_yarrow/ycipher.so  
+
 EXTRADEPSRCS=\
        $(srcdir)/t_nfold.c     \
        $(srcdir)/t_encrypt.c   \
@@ -41,15 +49,17 @@ EXTRADEPSRCS=\
 # NOTE: The t_cksum known checksum values are primarily for regression
 # testing.  They are not derived a priori, but are known to produce
 # checksums that interoperate.
-check-unix:: t_nfold t_encrypt t_prf t_prng t_hmac \
+#  check-unix:: t_nfold t_encrypt t_prf t_prng t_hmac \
+#
+check-unix:: t_prng t_nfold t_encrypt t_hmac t_prf\
                t_cksum4 t_cksum5 \
                aes-test  \
                t_mddriver4 t_mddriver \
                t_crc t_cts t_short
-       $(RUN_SETUP) $(VALGRIND) ./t_nfold
-       $(RUN_SETUP) $(VALGRIND) ./t_encrypt
        $(RUN_SETUP) $(VALGRIND) ./t_prng <$(srcdir)/t_prng.seed >t_prng.output && \
        diff t_prng.output $(srcdir)/t_prng.expected
+       $(RUN_SETUP) $(VALGRIND) ./t_nfold
+       $(RUN_SETUP) $(VALGRIND) ./t_encrypt
        $(RUN_SETUP) $(VALGRIND) ./t_hmac
        $(RUN_SETUP) $(VALGRIND) ./t_prf <$(srcdir)/t_prf.in >t_prf.output
        diff t_prf.output $(srcdir)/t_prf.expected
@@ -77,30 +87,31 @@ nfold.$(OBJEXT): $(srcdir)/../krb/nfold.c
        $(CC) -c $(ALL_CFLAGS) $(srcdir)/../krb/nfold.c
 
 t_encrypt$(EXEEXT): t_encrypt.$(OBJEXT) $(CRYPTO_DEPLIB) $(SUPPORT_DEPLIB)
-       $(CC_LINK) -o $@ t_encrypt.$(OBJEXT)  -lkrb5 -lk5crypto -lcom_err $(SUPPORT_LIB)
+       $(CC_LINK) -o $@ t_encrypt.$(OBJEXT)  -lkrb5 -lk5crypto -lcom_err $(SUPPORT_LIB)        \
+       $(PLUGINS_LIBS)
 
 t_prf$(EXEEXT): t_prf.$(OBJEXT) $(SUPPORT_DEPLIB)
-       $(CC_LINK) -o $@ t_prf.$(OBJEXT)  -lkrb5 -lk5crypto -lcom_err $(SUPPORT_LIB)
+       $(CC_LINK) -o $@ t_prf.$(OBJEXT)  -lkrb5 -lk5crypto -lcom_err $(SUPPORT_LIB) $(PLUGINS_LIBS)
 
 t_prng$(EXEEXT): t_prng.$(OBJEXT) $(SUPPORT_DEPLIB)
-       $(CC_LINK) -o $@ t_prng.$(OBJEXT)  -lk5crypto -lcom_err $(SUPPORT_LIB)
+       $(CC_LINK) -o $@ t_prng.$(OBJEXT)  -lk5crypto -lcom_err $(SUPPORT_LIB)  $(PLUGINS_LIBS)
 
 t_hmac$(EXEEXT): t_hmac.$(OBJEXT) $(CRYPTO_DEPLIB) $(SUPPORT_DEPLIB)
-       $(CC_LINK) -o $@ t_hmac.$(OBJEXT) $(K5CRYPTO_LIB) $(COM_ERR_LIB) $(SUPPORT_LIB)
+       $(CC_LINK) -o $@ t_hmac.$(OBJEXT) $(K5CRYPTO_LIB) $(COM_ERR_LIB) $(SUPPORT_LIB)  $(PLUGINS_LIBS)
 
 #t_pkcs5$(EXEEXT): t_pkcs5.$(OBJEXT) $(CRYPTO_DEPLIB) $(SUPPORT_DEPLIB)
-#      $(CC_LINK) -o $@ t_pkcs5.$(OBJEXT) $(K5CRYPTO_LIB) $(COM_ERR_LIB) $(SUPPORT_LIB)
+#      $(CC_LINK) -o $@ t_pkcs5.$(OBJEXT) $(K5CRYPTO_LIB) $(COM_ERR_LIB) $(SUPPORT_LIB) $(PLUGINS_LIBS)
 
 vectors$(EXEEXT): vectors.$(OBJEXT) $(CRYPTO_DEPLIB) $(SUPPORT_DEPLIB)
-       $(CC_LINK) -o $@ vectors.$(OBJEXT) $(K5CRYPTO_LIB) $(COM_ERR_LIB) $(SUPPORT_LIB)
+       $(CC_LINK) -o $@ vectors.$(OBJEXT) $(K5CRYPTO_LIB) $(COM_ERR_LIB) $(SUPPORT_LIB) $(PLUGINS_LIBS)
 
- t_cts$(EXEEXT): t_cts.$(OBJEXT) $(CRYPTO_DEPLIB) $(SUPPORT_DEPLIB)
+t_cts$(EXEEXT): t_cts.$(OBJEXT) $(CRYPTO_DEPLIB) $(SUPPORT_DEPLIB)
        $(CC_LINK) -o $@ t_cts.$(OBJEXT) \
-               $(K5CRYPTO_LIB) $(COM_ERR_LIB) $(SUPPORT_LIB)
+               $(K5CRYPTO_LIB) $(COM_ERR_LIB) $(SUPPORT_LIB) $(PLUGINS_LIBS)
 
 t_short$(EXEEXT): t_short.$(OBJEXT) $(CRYPTO_DEPLIB) $(SUPPORT_DEPLIB)
        $(CC_LINK) -o $@ t_short.$(OBJEXT) \
-               $(K5CRYPTO_LIB) $(COM_ERR_LIB) $(SUPPORT_LIB)
+               $(K5CRYPTO_LIB) $(COM_ERR_LIB) $(SUPPORT_LIB) $(PLUGINS_LIBS)
 
 t_cksum4.o: $(srcdir)/t_cksum.c
        $(CC) -DMD=4 $(ALL_CFLAGS) -o t_cksum4.o -c $(srcdir)/t_cksum.c
@@ -109,31 +120,31 @@ t_cksum5.o: $(srcdir)/t_cksum.c
        $(CC) -DMD=5 $(ALL_CFLAGS) -o t_cksum5.o -c $(srcdir)/t_cksum.c
 
 t_cksum4: t_cksum4.o $(CRYTPO_DEPLIB)
-       $(CC_LINK) -o t_cksum4 t_cksum4.o $(K5CRYPTO_LIB) $(COM_ERR_LIB) $(SUPPORT_LIB) $(LIBS)
+       $(CC_LINK) -o t_cksum4 t_cksum4.o $(K5CRYPTO_LIB) $(COM_ERR_LIB) $(SUPPORT_LIB) $(LIBS) $(PLUGINS_LIBS)
 
 t_cksum5: t_cksum5.o $(CRYPTO_DEPLIB)
-       $(CC_LINK) -o t_cksum5 t_cksum5.o $(K5CRYPTO_LIB) $(COM_ERR_LIB) $(SUPPORT_LIB) $(LIBS)
+       $(CC_LINK) -o t_cksum5 t_cksum5.o $(K5CRYPTO_LIB) $(COM_ERR_LIB) $(SUPPORT_LIB) $(LIBS) $(PLUGINS_LIBS)
 
 t_crc: t_crc.o $(CRYPTO_DEPLIB) $(SUPPORT_DEPLIB)
-       $(CC_LINK) -o $@ t_crc.o $(K5CRYPTO_LIB) $(SUPPORT_LIB)
+       $(CC_LINK) -o $@ t_crc.o $(K5CRYPTO_LIB) $(SUPPORT_LIB) $(PLUGINS_LIBS)
 
 aes-test: aes-test.$(OBJEXT) $(CRYPTO_DEPLIB)
-       $(CC_LINK) -o aes-test aes-test.$(OBJEXT) $(K5CRYPTO_LIB) $(COM_ERR_LIB) $(SUPPORT_LIB)
+       $(CC_LINK) -o aes-test aes-test.$(OBJEXT) $(K5CRYPTO_LIB) $(COM_ERR_LIB) $(SUPPORT_LIB) $(PLUGINS_LIBS)
 
 t_mddriver4.o: $(srcdir)/t_mddriver.c
        $(CC) -DMD=4 $(ALL_CFLAGS) -o t_mddriver4.o -c $(srcdir)/t_mddriver.c
 
-t_mddriver4: t_mddriver4.o  $(SUPPORT_DEPLIB) $(CRYPTO_DEPLIB)
-       $(CC_LINK) -DMD4  -o t_mddriver4 t_mddriver4.o -lk5crypto $(SUPPORT_LIB)
+t_mddriver4: t_mddriver4.o  $(SUPPORT_DEPLIB) $(CRYPTO_DEPLIB) 
+       $(CC_LINK) -DMD4  -o t_mddriver4 t_mddriver4.o -lk5crypto $(SUPPORT_LIB) $(PLUGINS_LIBS)
 
 t_mddriver: t_mddriver.o  $(SUPPORT_DEPLIB) $(CRYPTO_DEPLIB)
-       $(CC_LINK) -o t_mddriver t_mddriver.o -lk5crypto $(SUPPORT_LIB)
+       $(CC_LINK) -o t_mddriver t_mddriver.o -lk5crypto $(SUPPORT_LIB) $(PLUGINS_LIBS)
 
 t_kperf: t_kperf.o $(SUPPORT_DEPLIB) $(CRYPTO_DEPLIB)
-       $(CC_LINK) -o t_kperf t_kperf.o  $(SUPPORT_LIB) $(CRYPTO_DEPLIB)
+       $(CC_LINK) -o t_kperf t_kperf.o  $(SUPPORT_LIB) $(CRYPTO_DEPLIB) $(PLUGINS_LIBS)
 
 ytest: ytest.o shs.o $(SUPPORT_DEPLIB) $(CRYPTO_DEPLIB)
-       $(CC_LINK) -o ytest ytest.o  $(SUPPORT_LIB)  $(CRYPTO_DEPLIB)
+       $(CC_LINK) -o ytest ytest.o  $(SUPPORT_LIB)  $(CRYPTO_DEPLIB) $(PLUGINS_LIBS)
 
 
 
@@ -149,7 +160,7 @@ clean::
                t_kperf.o t_kperf t_short t_short.o \
                t_mddriver$(EXEEXT) $(OUTPRE)t_mddriver.$(OBJEXT)
 
-       -$(RM) t_prng.output
+# temp -$(RM) t_prng.output
        -$(RM) t_prf.output
 
 @lib_frag@
diff --git a/src/lib/crypto/crypto_tests/plugin_conf.yml b/src/lib/crypto/crypto_tests/plugin_conf.yml
new file mode 100755 (executable)
index 0000000..8e1b2ec
--- /dev/null
@@ -0,0 +1,17 @@
+- !Plugin
+  api: plugin_prng
+  type: service
+  constructor:
+    factory_name: plugin_default_factory
+    factory_type: static
+    plugin_name: plugin_yarrow_prng
+  Properties: null
+
+- !Plugin
+  api: audit
+  type: listener
+  constructor: 
+    factory_name: plugin_default_factory
+    factory_type: shared
+    plugin_name: undef
+  Properties: null
index c4f22bcd7484e634729ebdca3044f2c892cff3ab..63284d92568696498f2e50f3a0dcfcaf3d60afee 100644 (file)
@@ -31,6 +31,9 @@
  */
 
 #include "k5-int.h"
+#include <plugin_default_manager.h>
+#include <plugin_prng.h>
+
 
 #define MD5_K5BETA_COMPAT
 #define MD4_K5BETA_COMPAT
@@ -96,6 +99,14 @@ main(argc, argv)
     krb5_error_code       kret=0;
     krb5_data             plaintext;
     krb5_checksum         checksum, knowncksum;
+    plugin_manager* default_manager;
+    const char conf_path[] = "plugin_conf.yml";
+
+    default_manager = plugin_default_manager_get_instance();
+    set_plugin_manager_instance(default_manager);
+
+    plugin_manager_configure(conf_path);
+    plugin_manager_start();
 
     /* this is a terrible seed, but that's ok for the test. */
 
index aa6c4af2d49ebb5923422f6219b3f0d3d91914a3..c40b1916a043bb4feab28a3c9a1e6435c6e0248c 100644 (file)
@@ -34,6 +34,9 @@
 #include "k5-int.h"
 #include "etypes.h"
 #include <stdio.h>
+#include <plugin_default_manager.h>
+#include <plugin_prng.h>
+
 
 /* What enctypes should we test?*/
 krb5_enctype interesting_enctypes[] = {
@@ -98,6 +101,14 @@ main ()
     krb5_enc_data enc_out, enc_out2;
     krb5_keyblock *keyblock;
     krb5_key key;
+    plugin_manager* default_manager;
+    const char conf_path[] = "plugin_conf.yml";
+
+        default_manager = plugin_default_manager_get_instance();
+        set_plugin_manager_instance(default_manager);
+
+        plugin_manager_configure(conf_path);
+        plugin_manager_start();
 
     memset(iov, 0, sizeof(iov));
 
index 634667ab61f1313c1bcbc8510cdd359b76a91931..623aaedbb3b558fba0eb2f79c6bb68c260a078f0 100644 (file)
 
 #include "k5-int.h"
 #include <assert.h>
+#include <plugin_default_manager.h>
+#include <plugin_prng.h>
 
 int main () {
     krb5_error_code ret;
     krb5_data input, output;
     unsigned int source_id, seed_length;
     unsigned int i;
+    plugin_manager* default_manager;
+    const char conf_path[] = "plugin_conf.yml";
+
+        default_manager = plugin_default_manager_get_instance();
+        set_plugin_manager_instance(default_manager);
+
+        plugin_manager_configure(conf_path);
+        plugin_manager_start();
+
     while (1) {
         /* Read source*/
         if (scanf ("%u", &source_id ) == EOF )
index 9ddfd5e3d3140f1acc75f27ecd8481ee730e1ea4..f1285face3c3c0dc7c39c52b4a738ea4d8ec8907 100644 (file)
@@ -31,6 +31,9 @@
  */
 
 #include "k5-int.h"
+#include <plugin_default_manager.h>
+#include <plugin_prng.h>
+
 
 krb5_enctype interesting_enctypes[] = {
     ENCTYPE_DES_CBC_CRC,
@@ -116,6 +119,14 @@ main(int argc, char **argv)
 {
     int i;
     krb5_data notrandom;
+    plugin_manager* default_manager;
+    const char conf_path[] = "plugin_conf.yml";
+
+        default_manager = plugin_default_manager_get_instance();
+        set_plugin_manager_instance(default_manager);
+
+        plugin_manager_configure(conf_path);
+        plugin_manager_start();
 
     notrandom.data = "notrandom";
     notrandom.length = 9;
index 9e019115fe5559344adb9cc40ae7729a7e881eab..3e4f809510967cb14fa8870eca2d9aec92c2b183 100644 (file)
@@ -1,14 +1,15 @@
 mydir=lib/crypto/krb
 BUILDTOP=$(REL)..$(S)..$(S)..
 SUBDIRS= arcfour checksum crc32 dk \
-       prf rand2key old raw yarrow 
+       prf rand2key old raw 
 LOCALINCLUDES = -I$(srcdir) -I$(srcdir)/../@CRYPTO_IMPL@/enc_provider -I$(srcdir)/dk   \
                -I$(srcdir)/../@CRYPTO_IMPL@/hash_provider                              \
                -I$(srcdir)/prf -I$(srcdir)/rand2key                                    \
-               -I$(srcdir)/old -I$(srcdir)/raw -I$(srcdir)/yarrow                      \
+               -I$(srcdir)/old -I$(srcdir)/raw                         \
                -I$(srcdir)/../@CRYPTO_IMPL@/ -I$(srcdir)/../@CRYPTO_IMPL@/des          \
                -I$(srcdir)/../@CRYPTO_IMPL@/aes -I$(srcdir)/arcfour    \
-               -I$(srcdir)/../@CRYPTO_IMPL@/sha1 -I$(srcdir)/../@CRYPTO_IMPL@
+               -I$(srcdir)/../@CRYPTO_IMPL@/sha1 -I$(srcdir)/../@CRYPTO_IMPL@  \
+               -I$(BUILDTOP)/plugins/prng -I$(BUILDTOP)/plugin_core
 PROG_LIBPATH=-L$(TOPLIBD)
 PROG_RPATH=$(KRB5_LIBDIR)
 DEFS=
@@ -143,11 +144,11 @@ SRCS=\
 
 STOBJLISTS=arcfour/OBJS.ST checksum/OBJS.ST crc32/OBJS.ST      \
        dk/OBJS.ST prf/OBJS.ST rand2key/OBJS.ST                 \
-       old/OBJS.ST raw/OBJS.ST  yarrow/OBJS.ST  OBJS.ST
+       old/OBJS.ST raw/OBJS.ST  OBJS.ST
 
 SUBDIROBJLISTS=arcfour/OBJS.ST checksum/OBJS.ST crc32/OBJS.ST  \
        dk/OBJS.ST prf/OBJS.ST rand2key/OBJS.ST                 \
-       old/OBJS.ST raw/OBJS.ST  yarrow/OBJS.ST 
+       old/OBJS.ST raw/OBJS.ST  
 
 ##DOS##LIBOBJS = $(OBJS)
 
@@ -183,9 +184,6 @@ all-windows::
        cd ..\raw
        @echo Making in crypto\raw
        $(MAKE) -$(MFLAGS)
-       cd ..\yarrow
-       @echo Making in crypto\yarrow
-       $(MAKE) -$(MFLAGS)
        cd ..
 
 clean-windows::
@@ -213,9 +211,6 @@ clean-windows::
        cd ..\raw
        @echo Making clean in crypto\raw
        $(MAKE) -$(MFLAGS) clean
-       cd ..\yarrow
-       @echo Making clean in crypto\yarrow
-       $(MAKE) -$(MFLAGS) clean
        cd ..
 
 check-windows::
@@ -243,9 +238,6 @@ check-windows::
        cd ..\raw
        @echo Making check in crypto\raw
        $(MAKE) -$(MFLAGS) check
-       cd ..\yarrow
-       @echo Making check in crypto\yarrow
-       $(MAKE) -$(MFLAGS) check
        cd ..
 
 
index d720d35ec0e3ad4e2a192be7448b012bb7894fcf..2dcdf092ee729d13b8431ceba9cc1547554994e0 100644 (file)
@@ -338,8 +338,7 @@ prng.so prng.po $(OUTPRE)prng.$(OBJEXT): $(BUILDTOP)/include/autoconf.h \
   $(BUILDTOP)/include/krb5/krb5.h $(BUILDTOP)/include/osconf.h \
   $(BUILDTOP)/include/profile.h $(COM_ERR_DEPS) $(srcdir)/../builtin/enc_provider/enc_provider.h \
   $(srcdir)/../builtin/sha1/shs.h $(srcdir)/../builtin/yhash.h \
-  $(srcdir)/yarrow/yarrow.h $(srcdir)/yarrow/ycipher.h \
-  $(srcdir)/yarrow/ytypes.h $(top_srcdir)/include/k5-buf.h \
+  $(top_srcdir)/include/k5-buf.h \
   $(top_srcdir)/include/k5-err.h $(top_srcdir)/include/k5-gmt_mktime.h \
   $(top_srcdir)/include/k5-int-pkinit.h $(top_srcdir)/include/k5-int.h \
   $(top_srcdir)/include/k5-platform.h $(top_srcdir)/include/k5-plugin.h \
index ef326994a4726c73d1dcc60d023c50173417233b..962b63efc0a47a978ed336c47fe1811fa3ac86ef 100644 (file)
  */
 
 #include "k5-int.h"
-#include "enc_provider.h"
 #include <assert.h>
 #include "k5-thread.h"
 
-#include "yarrow.h"
-static Yarrow_CTX y_ctx;
-#define yarrow_lock krb5int_yarrow_lock
-k5_mutex_t yarrow_lock = K5_MUTEX_PARTIAL_INITIALIZER;
+#include <plugin_manager.h>
+#include <plugin_prng.h>
 
-/* Helper function to estimate entropy based on sample length
- * and where it comes from.
- */
 
-static size_t
-entropy_estimate(unsigned int randsource, size_t length)
-{
-    switch (randsource) {
-    case KRB5_C_RANDSOURCE_OLDAPI:
-        return 4 * length;
-    case KRB5_C_RANDSOURCE_OSRAND:
-        return 8 * length;
-    case KRB5_C_RANDSOURCE_TRUSTEDPARTY:
-        return 4 * length;
-    case KRB5_C_RANDSOURCE_TIMING:
-        return 2;
-    case KRB5_C_RANDSOURCE_EXTERNAL_PROTOCOL:
-        return 0;
-    default:
-        abort();
-    }
-    return 0;
-}
-
-int krb5int_prng_init(void)
-{
-    unsigned i, source_id;
-    int yerr;
-
-    yerr = k5_mutex_finish_init(&yarrow_lock);
-    if (yerr)
-        return yerr;
-
-    yerr = krb5int_yarrow_init (&y_ctx, NULL);
-    if (yerr != YARROW_OK && yerr != YARROW_NOT_SEEDED)
-        return KRB5_CRYPTO_INTERNAL;
-
-    for (i=0; i < KRB5_C_RANDSOURCE_MAX; i++ ) {
-        if (krb5int_yarrow_new_source(&y_ctx, &source_id) != YARROW_OK)
-            return KRB5_CRYPTO_INTERNAL;
-        assert (source_id == i);
-    }
-
-    return 0;
-}
 
 krb5_error_code KRB5_CALLCONV
 krb5_c_random_add_entropy(krb5_context context, unsigned int randsource,
                           const krb5_data *data)
 {
-    int yerr;
-
-    /* Make sure the mutex got initialized.  */
-    yerr = krb5int_crypto_init();
-    if (yerr)
-        return yerr;
-    /* Now, finally, feed in the data.  */
-    yerr = krb5int_yarrow_input(&y_ctx, randsource,
-                                data->data, data->length,
-                                entropy_estimate(randsource, data->length));
-    if (yerr != YARROW_OK)
-        return KRB5_CRYPTO_INTERNAL;
+    plhandle handle = plugin_manager_get_service("plugin_prng");
+
+    plugin_prng_seed(handle, context, randsource, data);
     return 0;
+
+
 }
 
 krb5_error_code KRB5_CALLCONV
@@ -106,110 +52,43 @@ krb5_c_random_seed(krb5_context context, krb5_data *data)
 }
 
 krb5_error_code KRB5_CALLCONV
-krb5_c_random_make_octets(krb5_context context, krb5_data *data)
+krb5_c_random_os_entropy(krb5_context context, int strong, int *success)
 {
-    int yerr;
-    yerr = krb5int_yarrow_output(&y_ctx, data->data, data->length);
-    if (yerr == YARROW_NOT_SEEDED) {
-        yerr = krb5int_yarrow_reseed(&y_ctx, YARROW_SLOW_POOL);
-        if (yerr == YARROW_OK)
-            yerr = krb5int_yarrow_output(&y_ctx, data->data, data->length);
-    }
-    if (yerr != YARROW_OK)
-        return KRB5_CRYPTO_INTERNAL;
+    plhandle handle = plugin_manager_get_service("plugin_prng");
+
+    plugin_prng_os_seed(handle, context, strong, success);
+
     return 0;
 }
 
-void
-krb5int_prng_cleanup (void)
+krb5_error_code KRB5_CALLCONV
+krb5_c_random_make_octets(krb5_context context, krb5_data *data)
 {
-    krb5int_yarrow_final (&y_ctx);
-    k5_mutex_destroy(&yarrow_lock);
-}
+    plhandle handle = plugin_manager_get_service("plugin_prng");
 
+    plugin_prng_rand(handle, context,  data);
 
-/*
- * Routines to get entropy from the OS.  For UNIX we try /dev/urandom
- * and /dev/random.  Currently we don't do anything for Windows.
- */
-#if defined(_WIN32)
-
-krb5_error_code KRB5_CALLCONV
-krb5_c_random_os_entropy(krb5_context context, int strong, int *success)
-{
-    if (success)
-        *success = 0;
     return 0;
 }
 
-#else /*Windows*/
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#ifdef HAVE_SYS_STAT_H
-#include <sys/stat.h>
-#endif
+int krb5int_prng_init(void)
+{
+    int ret = 0;
+    plhandle handle = plugin_manager_get_service("plugin_prng");
 
-/*
- * Helper function to read entropy from  a random device.  Takes the
- * name of a device, opens it, makes sure it is a device and if so,
- * reads entropy.  Returns  a boolean indicating whether entropy was
- * read.
- */
+    ret = plugin_prng_init(handle);
 
-static int
-read_entropy_from_device(krb5_context context, const char *device)
-{
-    krb5_data data;
-    struct stat sb;
-    int fd;
-    unsigned char buf[YARROW_SLOW_THRESH/8], *bp;
-    int left;
-
-    fd = open (device, O_RDONLY);
-    if (fd == -1)
-        return 0;
-    set_cloexec_fd(fd);
-    if (fstat(fd, &sb) == -1 || S_ISREG(sb.st_mode)) {
-        close(fd);
-        return 0;
-    }
-
-    for (bp = buf, left = sizeof(buf); left > 0;) {
-        ssize_t count;
-        count = read(fd, bp, (unsigned) left);
-        if (count <= 0) {
-            close(fd);
-            return 0;
-        }
-        left -= count;
-        bp += count;
-    }
-    close(fd);
-    data.length = sizeof (buf);
-    data.data = (char *) buf;
-    return (krb5_c_random_add_entropy(context, KRB5_C_RANDSOURCE_OSRAND,
-                                      &data) == 0);
+    return ret;
 }
 
-krb5_error_code KRB5_CALLCONV
-krb5_c_random_os_entropy(krb5_context context, int strong, int *success)
+void
+krb5int_prng_cleanup(void)
 {
-    int unused;
-    int *oursuccess = success ? success : &unused;
-
-    *oursuccess = 0;
-    /* If we are getting strong data then try that first.  We are
-       guaranteed to cause a reseed of some kind if strong is true and
-       we have both /dev/random and /dev/urandom.  We want the strong
-       data included in the reseed so we get it first.*/
-    if (strong) {
-        if (read_entropy_from_device(context, "/dev/random"))
-            *oursuccess = 1;
-    }
-    if (read_entropy_from_device(context, "/dev/urandom"))
-        *oursuccess = 1;
-    return 0;
+    plhandle handle = plugin_manager_get_service("plugin_prng");
+
+    plugin_prng_cleanup(handle);
+
+    return;
 }
 
-#endif /*Windows or pre-OSX Mac*/
+
diff --git a/src/lib/crypto/krb/yarrow/Makefile.in b/src/lib/crypto/krb/yarrow/Makefile.in
deleted file mode 100644 (file)
index 55ae16c..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-mydir=lib/crypto/krb/yarrow
-BUILDTOP=$(REL)..$(S)..$(S)..$(S)..
-LOCALINCLUDES = -I$(srcdir)/.. \
-               -I$(srcdir)/../../@CRYPTO_IMPL@         \
-               -I$(srcdir)/../../@CRYPTO_IMPL@/sha1    \
-               -I$(srcdir)/../../@CRYPTO_IMPL@/enc_provider
-DEFS=
-
-##DOS##BUILDTOP = ..\..\..\..
-##DOS##PREFIXDIR=yarrow
-##DOS##OBJFILE=..\$(OUTPRE)yarrow.lst
-
-PROG_LIBPATH=-L$(TOPLIBD)
-PROG_RPATH=$(KRB5_LIBDIR)
-
-STLIBOBJS=\
-       yarrow.o \
-       ycipher.o
-OBJS=\
-       $(OUTPRE)yarrow.$(OBJEXT) \
-       $(OUTPRE)ycipher.$(OBJEXT)
-
-SRCS=\
-       $(srcdir)/yarrow.c \
-       $(srcdir)/ycipher.c 
-
-##DOS##LIBOBJS = $(OBJS)
-
-all-unix:: all-libobjs
-
-includes:: depend
-
-depend:: $(SRCS)
-
-clean-unix:: clean-libobjs
-
-@libobj_frag@
-
index b6d7353be8d198db9ba3ef1c62384bd4789fb2d0..76de3fc369c734e5a4883e9c10a4b95ed047c72f 100644 (file)
@@ -1,3 +1,9 @@
+krb5_c_random_os_entropy
+krb5int_crypto_init
+shsUpdate
+shsInit
+shsFinal
+krb5int_enc_aes256
 krb5_c_make_random_key
 krb5_c_encrypt_length
 krb5_process_key
@@ -13,7 +19,6 @@ is_coll_proof_cksum
 krb5_init_random_key
 krb5_c_string_to_key_with_params
 krb5_c_random_make_octets
-krb5_c_random_os_entropy
 krb5_c_decrypt
 krb5_c_crypto_length
 krb5_c_block_size
diff --git a/src/plugin_core/Makefile.in b/src/plugin_core/Makefile.in
new file mode 100644 (file)
index 0000000..9aca218
--- /dev/null
@@ -0,0 +1,36 @@
+mydir=plugin_core
+BUILDTOP=$(REL)..
+PROG_LIBPATH=-L$(TOPLIBD)
+PROG_RPATH=$(KRB5_LIBDIR)
+DEFS=
+
+LOCALINCLUDES = -I$(srcdir)/include/krb5  -I$(srcdir)/. -I$(srcdir)/../plugins/prng
+
+LIBBASE=plugin_core
+LIBMAJOR=0
+LIBMINOR=0
+SO_EXT=.so
+
+LIBS_UTILS = -lyaml
+
+SHLIB_DIRS=-L$(TOPLIBD)
+SHLIB_RDIRS=$(KRB5_LIBDIR)
+STOBJLISTS=OBJS.ST ../plugins/prng/OBJS.SH  
+
+SHLIB_EXPLIBS=  $(LIBS_UTILS)
+STLIBOBJS= plugin_manager.o plugin_factory.o yaml_parser.o
+
+SRCS= plugin_manager.c plugin_factory.c yaml_parser.c
+
+# all-unix:: all-libobjs
+all-unix:: all-liblinks
+install-unix:: install-libs
+clean-unix:: clean-libs clean-libobjs
+
+clean::
+       $(RM) lib$(LIBBASE)$(SO_EXT)
+
+@libnover_frag@
+@libobj_frag@
+
diff --git a/src/plugin_core/deps b/src/plugin_core/deps
new file mode 100644 (file)
index 0000000..0e60a31
--- /dev/null
@@ -0,0 +1,7 @@
+plugin_manager.so plugin_manager.po $(OUTPRE)plugin_manager.$(OBJEXT): \
+  $(BUILDTOP)/include/krb5/krb5.h $(COM_ERR_DEPS) $(top_srcdir)/plugin_core/plugin_manager.h \
+  plugin_manager.c
+plugin_factory.so plugin_factory.po $(OUTPRE)plugin_factory.$(OBJEXT): \
+  $(BUILDTOP)/include/krb5/krb5.h $(COM_ERR_DEPS) $(top_srcdir)/plugin_core/plugin_factory.h \
+  $(top_srcdir)/plugin_core/plugin_manager.h \
+  plugin_factory.c
diff --git a/src/plugin_core/impl/Makefile.in b/src/plugin_core/impl/Makefile.in
new file mode 100644 (file)
index 0000000..1714578
--- /dev/null
@@ -0,0 +1,29 @@
+mydir=impl
+BUILDTOP=$(REL)../..
+PROG_LIBPATH=-L$(TOPLIBD)
+PROG_RPATH=$(KRB5_LIBDIR)
+DEFS=
+
+LOCALINCLUDES = -I$(srcdir)/../../include/krb5  -I$(srcdir)/.  \
+               -I$(srcdir)/../../plugins/prng/plugin_yarrow -I$(srcdir)/../../plugins/prng     \
+               -I$(srcdir)/..
+
+STLIBOBJS= plugin_default_factory.o plugin_default_manager.o
+
+OBJS=\
+       $(OUTPRE)plugin_default_manager.$(OBJEXT) \
+       $(OUTPRE)plugin_default_factory.$(OBJEXT) 
+
+SRCS= plugin_default_factory.c plugin_default_manager.c
+
+all-unix:: all-libobjs
+
+includes:: depend
+
+depend:: $(SRCS)
+
+clean-unix:: clean-libobjs
+
+@libobj_frag@
+
diff --git a/src/plugin_core/impl/deps b/src/plugin_core/impl/deps
new file mode 100644 (file)
index 0000000..e04372d
--- /dev/null
@@ -0,0 +1,14 @@
+plugin_default_manager.so plugin_default_manager.po $(OUTPRE)plugin_default_manager.$(OBJEXT): \
+  $(BUILDTOP)/include/krb5/krb5.h $(COM_ERR_DEPS) $(top_srcdir)/plugin_core/plugin_manager.h \
+  $(top_srcdir)/plugin_core/plugin_manager.h \
+  $(top_srcdir)/plugin_core/yaml_parser.h \
+  $(top_srcdir)/plugin_core/impl/plugin_default_manager.h \
+  $(top_srcdir)/plugin_core/impl/plugin_default_factory.h \
+  plugin_default_manager.c
+plugin_default_factory.so plugin_default_factory.po $(OUTPRE)plugin_default_factory.$(OBJEXT): \
+  $(BUILDTOP)/include/krb5/krb5.h $(COM_ERR_DEPS) $(top_srcdir)/plugin_core/plugin_factory.h \
+  $(top_srcdir)/plugin_core/plugin_manager.h \
+  $(top_srcdir)/plugins/prng/plugin_yarrow/plugin_prng_impl.h \
+  $(top_srcdir)/plugin_core/impl/plugin_default_manager.h \
+  $(top_srcdir)/plugin_core/impl/plugin_default_factory.h \
+  plugin_default_factory.c
diff --git a/src/plugin_core/impl/plugin_default_factory.c b/src/plugin_core/impl/plugin_default_factory.c
new file mode 100644 (file)
index 0000000..2906760
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * plugin_default_factory.c
+ *
+ */
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "plugin_manager.h"
+#include "plugin_factory.h"
+#include "plugin_prng_impl.h"
+#include "plugin_default_factory.h"
+
+static plugin_factory* _default_factory_instance = NULL;
+
+static plugin_descr _table[] = {
+        {"plugin_yarrow_prng", plugin_yarrow_prng_create},
+        //{"plugin_simple_prng", plugin_simple_prng_create},
+        {"plugin_ldap_audit", NULL},
+        {NULL,NULL}
+};
+
+
+/* Factory API implementation */
+static void
+_get_factory_content (const char* container[]) {
+    plugin_descr *ptr = NULL;
+    int i = 0;
+    for( ptr = _table; ptr->plugin_name != NULL; ptr++,i++) {
+        container[i] = ptr->plugin_name;
+    }
+}
+
+static plhandle
+_create_api (const char* plugin_name)
+{
+    plhandle handle;
+    plugin_descr *ptr = NULL;
+
+    handle.api = NULL;
+    for( ptr = _table; ptr->plugin_name != NULL; ptr++) {
+        if (strcmp(ptr->plugin_name, plugin_name) == 0) {
+            handle = ptr->plugin_creator();
+            break;
+        }
+    }
+    return handle;
+}
+
+
+FactoryHandle
+plugin_default_factory_get_instance()
+{
+    plugin_factory* instance = _default_factory_instance;
+    FactoryHandle handle;
+
+    if(_default_factory_instance == NULL) {
+        instance = (plugin_factory*) malloc(sizeof(plugin_factory));
+        memset(instance, 0, sizeof(plugin_factory));
+        instance->get_factory_content = _get_factory_content;
+        instance->create_api = _create_api;
+        _default_factory_instance = instance;
+    }
+    handle.api = instance;
+    return (handle);
+}
+
diff --git a/src/plugin_core/impl/plugin_default_factory.h b/src/plugin_core/impl/plugin_default_factory.h
new file mode 100644 (file)
index 0000000..66b5cfe
--- /dev/null
@@ -0,0 +1,14 @@
+/*
+ * plugin_default_factory.h
+ *
+ */
+
+#ifndef SIMPLE_PLUGIN_FACTORY_H_
+#define SIMPLE_PLUGIN_FACTORY_H_
+
+#include <plugin_factory.h>
+
+FactoryHandle plugin_default_factory_get_instance(void);
+
+
+#endif /* SIMPLE_PLUGIN_FACTORY_H_ */
diff --git a/src/plugin_core/impl/plugin_default_manager.c b/src/plugin_core/impl/plugin_default_manager.c
new file mode 100644 (file)
index 0000000..dc062d0
--- /dev/null
@@ -0,0 +1,255 @@
+/*
+ * plugin_default_manager.c
+ *
+ */
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <plugin_manager.h>
+#include <plugin_factory.h>
+#include "plugin_default_manager.h"
+#include "plugin_default_factory.h"
+#include "yaml_parser.h"
+
+
+static plugin_manager* _instance = NULL;
+//static plhandle* _prng_instance = NULL;
+
+static plugin_factory_descr _table[] = {
+        {"plugin_default_factory", plugin_default_factory_get_instance},
+        {NULL, NULL}
+};
+
+static FactoryHandle
+_load_factory (const char* factory_name, const char* factory_type)
+{
+    FactoryHandle handle;
+    plugin_factory_descr *ptr = NULL;
+
+    handle.api = NULL;
+    for( ptr = _table; ptr->factory_name != NULL; ptr++) {
+        if (strcmp(ptr->factory_name, factory_name) == 0) {
+            handle = ptr->factory_creator();
+            break;
+        }
+    }
+    return handle;
+}
+
+static registry_data*
+_create_registry()
+{
+    registry_data* registry = (registry_data*) malloc(sizeof(registry_data));
+    memset(registry, 0, sizeof(registry_data));
+
+    return registry;
+}
+
+static void
+_extend_registry (registry_data* data, int ext_n)
+{
+    if(data->registry_max_size == 0) {
+        data->table = NULL;
+    }
+    data->table = (reg_entry*) realloc(data->table, ext_n * sizeof(reg_entry));
+    memset(data->table + data->registry_max_size, 0, ext_n * sizeof(reg_entry));
+    data->registry_max_size += ext_n;
+}
+
+static reg_entry*
+_search_registry (registry_data* data, const char* api_name)
+{
+    int i = 0;
+    reg_entry* ptr = data->table;
+
+    for(i = 0; i < data->registry_size; i++,ptr++) {
+        if(strcmp(api_name, ptr->api_name) == 0) {
+            return ptr;
+        }
+    }
+    return NULL;
+}
+
+static plhandle
+_create_api(const char* plugin_name, const char* factory_name,
+            const char* factory_type, config_node* properties)
+{
+    plhandle p_handle;
+    FactoryHandle f_handle = _load_factory(factory_name, factory_type);
+    p_handle = create_api(f_handle, plugin_name);
+
+    return(p_handle);
+}
+
+static int
+_register_api(registry_data* data, const char* api_name,
+              const char* plugin_type, plhandle handle)
+{
+    const int extension_size = 32;
+    reg_entry* entry = NULL;
+    plhandle* next;
+    int ret = 0;
+
+    if(data->registry_size == data->registry_max_size) {
+        _extend_registry(data, extension_size);
+    }
+    entry = _search_registry(data, api_name);
+    if(entry == NULL) {
+        entry = data->table + data->registry_size;
+        data->registry_size++;
+    }
+    if(entry->size && strcmp(plugin_type, "service") == 0) {
+        //printf("%s is already registered, only one plugin is allowed per service\n", api_name);
+        ret = 0;
+    } else {
+        strcpy(entry->api_name, api_name);
+        next = (plhandle*) malloc(sizeof(plhandle));
+        memset(next, 0, sizeof(plhandle));
+        next->api = handle.api;
+        if(entry->first == NULL) {
+            entry->first = next;
+            entry->last = next;
+        } else {
+            entry->last->next = next;
+            entry->last = next;
+        }
+        entry->size++;
+        ret = 1;
+    }
+    return ret;
+}
+
+static void
+_configure_plugin(manager_data* mdata, config_node* plugin_node)
+{
+    config_node* p = NULL;
+    config_node* properties = NULL;
+    const char* plugin_api = NULL;
+    const char* factory_name = NULL;
+    const char* factory_type = NULL;
+    const char* plugin_name = NULL;
+    const char* plugin_type = NULL;
+    plhandle handle;
+
+    for (p = plugin_node->node_value.seq_value.start; p != NULL; p = p->next) {
+        if(strcmp(p->node_name, "api") == 0) {
+            plugin_api = p->node_value.str_value;
+        } else if(strcmp(p->node_name, "type") == 0) {
+            plugin_type = p->node_value.str_value;
+        } else if(strcmp(p->node_name, "constructor") == 0) {
+            config_node* q = NULL;
+            for(q = p->node_value.seq_value.start; q != NULL; q = q->next) {
+                if(strcmp(q->node_name, "factory_name") == 0) {
+                    factory_name = q->node_value.str_value;
+                } else if(strcmp(q->node_name, "factory_type") == 0) {
+                    factory_type = q->node_value.str_value;
+                } else if(strcmp(q->node_name, "plugin_name") == 0) {
+                    plugin_name = q->node_value.str_value;
+                }
+            }
+        } else if(strcmp(p->node_name, "properties") == 0) {
+            properties = p;
+        }
+    }
+    /*printf("**Start**\n");
+    printf("api=%s\n", plugin_api);
+    printf("factory=%s\n", factory_name);
+    printf("factory_type=%s\n", factory_type);
+    printf("plugin_name=%s\n", plugin_name);
+    printf("plugin_type=%s\n", plugin_type);
+    printf("**End**\n");
+*/
+    handle = _create_api(plugin_name, factory_name, factory_type, properties);
+    if(handle.api != NULL) {
+        if(!(_register_api(mdata->registry,plugin_api, plugin_type, handle))) {
+         /*   printf("Failed to register %s for %s(factory=%s,plugin_type=%s)\n",
+                    plugin_name, plugin_api, factory_name, plugin_type);
+           */
+              exit(1);
+        }
+    } else {
+        /*printf("Failed to configure plugin: api=%s, plugin_name=%s,factory=%s\n",
+                plugin_api, plugin_name, factory_name);
+*/
+    }
+    return;
+}
+
+/* Plugin API implementation */
+static void
+_configure(void* data, const char* path)
+{
+    manager_data* mdata = (manager_data*) data;
+    config_node* stream = NULL;
+    config_node* p = NULL;
+    stream = parse_file(path);
+
+    for(p = stream->node_value.seq_value.start; p != NULL; p = p->next) {
+        config_node* q = NULL;
+        for(q = p->node_value.seq_value.start; q != NULL; q = q->next) {
+            if(strcmp(q->node_tag,"!Plugin") == 0) {
+                _configure_plugin(mdata, q);
+            } else {
+                printf("Failed to find plugin configuration\n");
+            }
+        }
+    }
+}
+
+static void
+_start(void* data)
+{
+    return;
+}
+
+static void
+_stop(void* data)
+{
+    return;
+}
+
+static plhandle
+_getService(void* data, const char* service_name)
+{
+    plhandle handle;
+    manager_data* mdata = (manager_data*) data;
+    reg_entry* entry = _search_registry(mdata->registry, service_name);
+
+    memset(&handle, 0, sizeof handle);
+    if(entry) {
+        handle = *(entry->first);
+    } else {
+        printf("service %s is not available\n", service_name);
+    }
+
+    return handle;
+}
+
+static manager_data*
+_init_data()
+{
+    manager_data* data = (manager_data*) malloc(sizeof(manager_data));
+    memset(data, 0, sizeof(manager_data));
+    data->registry = _create_registry();
+
+    return data;
+}
+
+plugin_manager*
+plugin_default_manager_get_instance()
+{
+    plugin_manager* instance = _instance;
+
+    if(_instance == NULL) {
+        instance = (plugin_manager*) malloc(sizeof(plugin_manager));
+        memset(instance, 0, sizeof(plugin_manager));
+        instance->data = _init_data();
+        instance->configure = _configure;
+        instance->start = _start;
+        instance->stop = _stop;
+        instance->getService = _getService;
+        _instance = instance;
+    }
+    return (instance);
+}
+
diff --git a/src/plugin_core/impl/plugin_default_manager.h b/src/plugin_core/impl/plugin_default_manager.h
new file mode 100644 (file)
index 0000000..d078883
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * plugin_default_manager.h
+ *
+ */
+
+#ifndef PLUGIN_DEFAULT_MANAGER_H_
+#define PLUGIN_DEFAULT_MANAGER_H_
+
+#include <plugin_manager.h>
+
+typedef struct {
+    char api_name[512];
+    plhandle* first;
+    plhandle* last;
+    int size;
+} reg_entry;
+
+typedef struct {
+    reg_entry* table;
+    long registry_size;
+    long registry_max_size;
+} registry_data;
+
+typedef struct {
+    registry_data* registry;
+} manager_data;
+
+plugin_manager* plugin_default_manager_get_instance(void);
+
+#endif /* PLUGIN_DEFAULT_MANAGER_H_ */
diff --git a/src/plugin_core/impl/plugin_impl.exports b/src/plugin_core/impl/plugin_impl.exports
new file mode 100644 (file)
index 0000000..e496f15
--- /dev/null
@@ -0,0 +1,2 @@
+plugin_default_factory_get_instance
+plugin_default_manager_get_instance
diff --git a/src/plugin_core/plugin_core.exports b/src/plugin_core/plugin_core.exports
new file mode 100644 (file)
index 0000000..b23a829
--- /dev/null
@@ -0,0 +1,8 @@
+get_factory_content
+plugin_manager_configure
+plugin_manager_get_service
+set_plugin_manager_instance
+plugin_manager_start
+plugin_manager_stop
+create_api
+parse_file
diff --git a/src/plugin_core/plugin_factory.c b/src/plugin_core/plugin_factory.c
new file mode 100644 (file)
index 0000000..1ac3df1
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * plugin_factory.c
+ *
+ */
+
+#include <string.h>
+#include "plugin_factory.h"
+
+void
+get_factory_content (FactoryHandle handle, const char* container[])
+{
+       plugin_factory* factory = (plugin_factory*) handle.api;
+       factory->get_factory_content(container);
+}
+
+plhandle
+create_api (FactoryHandle handle, const char* plugin_name)
+{
+       plugin_factory* factory = (plugin_factory*) handle.api;
+       return factory->create_api(plugin_name);
+}
diff --git a/src/plugin_core/plugin_factory.h b/src/plugin_core/plugin_factory.h
new file mode 100644 (file)
index 0000000..474ad46
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * plugin_factory.h
+ *
+ */
+#ifndef PLUGIN_FACTORY_H_
+#define PLUGIN_FACTORY_H_
+
+#include "plugin_manager.h"
+
+/* Plugin factory API */
+typedef struct {
+       void *api;
+} FactoryHandle;
+
+typedef struct {
+       const char* factory_name;
+       FactoryHandle (*factory_creator)();
+} plugin_factory_descr;
+
+typedef struct {
+       const char* plugin_name;
+       plhandle (*plugin_creator)();
+} plugin_descr;
+
+typedef struct {
+       void (*get_factory_content)(const char* []);
+       plhandle (*create_api)(const char*);
+} plugin_factory;
+
+/* Utility functions */
+void get_factory_content(FactoryHandle handle, const char* container[]);
+plhandle create_api(FactoryHandle handle, const char* plugin_name);
+
+#endif /* PLUGIN_FACTORY_H_ */
diff --git a/src/plugin_core/plugin_manager.c b/src/plugin_core/plugin_manager.c
new file mode 100644 (file)
index 0000000..a702839
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * plugin_manager.c
+ *
+ */
+#include "plugin_manager.h"
+#include "string.h"
+
+
+static plugin_manager* _instance = NULL;
+
+void
+set_plugin_manager_instance(plugin_manager* manager) {
+       _instance = manager;
+}
+
+void
+plugin_manager_configure(const char* path)
+{
+       if(_instance != NULL) {
+               _instance->configure(_instance->data, path);
+       }
+}
+
+void plugin_manager_start()
+{
+       if(_instance != NULL) {
+               _instance->start(_instance->data);
+       }
+}
+
+void plugin_manager_stop()
+{
+       if(_instance != NULL) {
+               _instance->stop(_instance->data);
+       }
+}
+
+plhandle
+plugin_manager_get_service(const char* service_name)
+{
+       plhandle handle;
+       if(_instance != NULL) {
+               handle = _instance->getService(_instance->data, service_name);
+       } else {
+               handle.api = NULL;
+       }
+       return handle;
+}
+
+
+
diff --git a/src/plugin_core/plugin_manager.h b/src/plugin_core/plugin_manager.h
new file mode 100644 (file)
index 0000000..a51fff8
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * plugin_manager.h
+ *
+ */
+
+#ifndef PLUGIN_MANAGER_H_
+#define PLUGIN_MANAGER_H_
+
+#include <k5-int.h>
+
+
+typedef struct {
+       void* data;
+       void (*configure)(void* data, const char*);
+       void (*start)(void* data);
+       void (*stop)(void* data);
+       plhandle (*getService)(void* data, const char*);
+} plugin_manager;
+
+void set_plugin_manager_instance(plugin_manager*);
+
+/* Utility functions */
+void plugin_manager_configure(const char*);
+void plugin_manager_start();
+void plugin_manager_stop();
+plhandle plugin_manager_get_service(const char*);
+
+#endif /* PLUGIN_MANAGER_H_ */
diff --git a/src/plugin_core/yaml_parser.c b/src/plugin_core/yaml_parser.c
new file mode 100644 (file)
index 0000000..0387789
--- /dev/null
@@ -0,0 +1,199 @@
+/*
+ * yaml_parser.c
+ *
+ */
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+#include <yaml.h>
+#include "yaml_parser.h"
+
+static config_node*
+_create_new_node(const char* name, const char* type,
+                 const char* tag, config_node* parent)
+ {
+    config_node* anode = (config_node*) malloc(sizeof(config_node));
+    memset(anode, 0, sizeof(config_node));
+    if(name != NULL && strlen(name)) {
+        strcpy(anode->node_name, name);
+    }
+    if(type != NULL && strlen(type)) {
+        strcpy(anode->node_type, type);
+    }
+    if(tag != NULL && strlen(tag)) {
+        strcpy(anode->node_tag, tag);
+    }
+
+    anode->parent = parent;
+
+    return anode;
+ }
+
+static void
+_append_node(config_node* anode, config_node* achild)
+ {
+    if(anode->node_value.seq_value.start == NULL) {
+        anode->node_value.seq_value.start = achild;
+        anode->node_value.seq_value.end = achild;
+    } else {
+        anode->node_value.seq_value.end->next = achild;
+        anode->node_value.seq_value.end = achild;
+    }
+ }
+
+void
+walk (config_node* root)
+{
+    config_node* anode = root;
+    config_node* start = anode->node_value.seq_value.start;
+    config_node* ptr = NULL;
+    if(strcmp(root->node_type, "SCALAR") == 0) {
+        //printf("%s: %s=%s\n", root->node_type,
+          //     root->node_name, root->node_value.str_value);
+    } else {
+     //   printf("%s: %s: %s \n", root->node_name, root->node_type, root->node_tag);
+        for(ptr = start; ptr != NULL; ptr = ptr->next) {
+            walk(ptr);
+        }
+    }
+}
+
+static void
+_process_event(yaml_parser_t* parser, yaml_event_type_t parent_event_type,
+              config_node* parent_node)
+{
+    config_node* anode = NULL;
+    char* attribute = NULL;
+    yaml_event_t event;
+    int done = 0;
+    int error = 0;
+
+    while (!done) {
+        /* Get the next event. */
+        if (!yaml_parser_parse(parser, &event)) {
+            error = 1;
+            break;
+        }
+        switch(parent_event_type) {
+            case YAML_NO_EVENT:
+                if(event.type == YAML_STREAM_START_EVENT) {
+                    _process_event(parser, event.type, parent_node);
+                    done = 1;
+                } else {
+                    //printf("Error: unexpected event %d\n", event.type);
+                }
+                break;
+            case YAML_STREAM_START_EVENT:
+                if(event.type == YAML_DOCUMENT_START_EVENT) {
+                    anode = _create_new_node("document", "DOC",
+                                             (char*)event.data.scalar.tag, parent_node);
+                    _append_node(parent_node, anode);
+                    _process_event(parser, event.type, anode);
+                }  else if(event.type == YAML_STREAM_END_EVENT) {
+                    done = 1;
+                } else {
+                    //printf("Error: unexpected event %d\n", event.type);
+                }
+                break;
+            case YAML_DOCUMENT_START_EVENT:
+                if(event.type == YAML_SCALAR_EVENT) {
+                    strcpy(parent_node->node_type, "SCALAR");
+                    parent_node->node_value.str_value = strdup((char*)event.data.scalar.value);
+                } else if(event.type == YAML_SEQUENCE_START_EVENT) {
+                    strcpy(parent_node->node_type, "SEQ");
+                    _process_event(parser, event.type, parent_node);
+                } else if(event.type == YAML_MAPPING_START_EVENT) {
+                    strcpy(parent_node->node_type, "MAP");
+                    _process_event(parser, event.type, parent_node);
+                }  else if(event.type == YAML_DOCUMENT_END_EVENT) {
+                    done = 1;
+                } else {
+                    // printf("Error: unexpected event %d\n", event.type);
+                }
+            break;
+            case YAML_SEQUENCE_START_EVENT:
+                if(event.type == YAML_SCALAR_EVENT) {
+                    anode = _create_new_node("", "SCALAR",
+                                             (char*)event.data.scalar.tag, parent_node);
+                    anode->node_value.str_value = strdup((char*) event.data.scalar.value);
+                    _append_node(parent_node, anode);
+                } else if(event.type == YAML_SEQUENCE_START_EVENT) {
+                    anode = _create_new_node("", "SEQ",
+                                             (char*)event.data.scalar.tag, parent_node);
+                    _append_node(parent_node, anode);
+                    _process_event(parser, event.type, anode);
+                } else if(event.type == YAML_MAPPING_START_EVENT) {
+                    anode = _create_new_node("", "MAP",
+                                             (char*)event.data.scalar.tag, parent_node);
+                    _append_node(parent_node, anode);
+                    _process_event(parser, event.type, anode);
+                }  else if(event.type == YAML_SEQUENCE_END_EVENT) {
+                    done = 1;
+                } else {
+                    //printf("Error: unexpected event %d\n", event.type);
+                }
+            break;
+            case YAML_MAPPING_START_EVENT:
+                if(event.type == YAML_SCALAR_EVENT) {
+                    if(attribute) {
+                        anode = _create_new_node(attribute, "SCALAR",
+                                                 (char*)event.data.scalar.tag, parent_node);
+                        anode->node_value.str_value = strdup((char*)event.data.scalar.value);
+                        _append_node(parent_node, anode);
+                        free(attribute);
+                        attribute = NULL;
+                    } else {
+                        attribute = strdup((char*)event.data.scalar.value);
+                    }
+                } else if(event.type == YAML_SEQUENCE_START_EVENT) {
+                    assert(attribute);
+                    anode = _create_new_node(attribute, "SEQ",
+                                             (char*)event.data.scalar.tag, parent_node);
+                    _append_node(parent_node, anode);
+                    free(attribute);
+                    attribute = NULL;
+                    _process_event(parser, event.type, anode);
+                } else if(event.type == YAML_MAPPING_START_EVENT) {
+                    assert(attribute);
+                    anode = _create_new_node(attribute, "MAP",
+                                             (char*)event.data.scalar.tag, parent_node);
+                    _append_node(parent_node, anode);
+                    free(attribute);
+                    attribute = NULL;
+                    _process_event(parser, event.type, anode);
+                } else if(event.type == YAML_MAPPING_END_EVENT) {
+                    done = 1;
+                } else {
+                    //printf("Error: unexpected event %d\n", event.type);
+                }
+            break;
+            default:
+            break;
+                //printf("Unexpected event %d\n", event.type);
+        }
+        /* The application is responsible for destroying the event object. */
+        yaml_event_delete(&event);
+    }
+}
+
+config_node*
+parse_file(const char* path)
+{
+    yaml_parser_t parser;
+    FILE *infile;
+    config_node* stream_node = _create_new_node("all", "STREAM", "", NULL);
+
+    /* Create the Parser object. */
+    yaml_parser_initialize(&parser);
+    /* Set a file input. */
+    infile = fopen(path, "rb");
+    yaml_parser_set_input_file(&parser, infile);
+    /* Read the event sequence. */
+    _process_event(&parser, YAML_NO_EVENT, stream_node);
+    yaml_parser_delete(&parser);
+    fclose(infile);
+
+    return(stream_node);
+
+}
+
diff --git a/src/plugin_core/yaml_parser.h b/src/plugin_core/yaml_parser.h
new file mode 100644 (file)
index 0000000..de68717
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * yaml_parser.h
+ *
+ */
+
+#ifndef YAML_PARSER_H_
+#define YAML_PARSER_H_
+
+#include <yaml.h>
+
+typedef struct _node* p_node;
+
+typedef struct _sequence {
+       p_node start;
+       p_node end;
+} node_sequence;
+
+typedef struct _node {
+       char node_name[1024];
+       char node_type[16];
+       char node_tag[256];
+       union {
+               char* str_value;
+               node_sequence seq_value;
+       } node_value;
+       p_node parent;
+       p_node next;
+} config_node;
+
+config_node* parse_file(const char* path);
+
+void walk (config_node* root);
+
+#endif /* YAML_PARSER_H_ */
+
diff --git a/src/plugins/prng/Makefile.in b/src/plugins/prng/Makefile.in
new file mode 100644 (file)
index 0000000..5e929e3
--- /dev/null
@@ -0,0 +1,26 @@
+mydir=plugins/prng
+BUILDTOP=$(REL)../..
+KRB5_RUN_ENV = @KRB5_RUN_ENV@
+KRB5_CONFIG_SETUP =
+PROG_LIBPATH=-L$(TOPLIBD)
+PROG_RPATH=$(KRB5_LIBDIR)
+MODULE_INSTALL_DIR = 
+DEFS=@DEFS@
+
+LOCALINCLUDES = -I../../include/krb5 -I. -I../../plugin_core
+
+STLIBOBJS=  plugin_prng.o  
+OBJS= $(OUTPRE)plugin_prng.$(OBJEXT)
+SRCS=  plugin_prng.c  
+
+#all-unix:: all-liblinks
+all-unix:: all-libobjs
+
+includes:: depend
+
+depend:: $(SRCS)
+
+clean-unix::  clean-libobjs
+
+@libobj_frag@
+
diff --git a/src/plugins/prng/deps b/src/plugins/prng/deps
new file mode 100644 (file)
index 0000000..bdde2dd
--- /dev/null
@@ -0,0 +1,13 @@
+# 
+# Generated makefile dependencies follow.
+#
+plugin_prng.so plugin_prng.po $(OUTPRE)plugin_prng.$(OBJEXT): \
+  $(BUILDTOP)/include/krb5/krb5.h $(COM_ERR_DEPS) $(top_srcdir)/plugins/prng/plugin_prng.h \
+  $(top_srcdir)/plugin_core/plugin_manager.h \
+  $(top_srcdir)/plugin_core/plugin_factory.h \
+  plugin_prng.c
+plugin_prng_impl.so plugin_prng_impl.po $(OUTPRE)plugin_prng_impl.$(OBJEXT): \
+  $(BUILDTOP)/include/krb5/krb5.h $(COM_ERR_DEPS) $(top_srcdir)/plugins/prng/plugin_prng_impl.h \
+  $(top_srcdir)/plugin_core/plugin_manager.h \
+  $(top_srcdir)/plugin_core/plugin_factory.h \
+  plugin_prng_impl.c
diff --git a/src/plugins/prng/plugin_prng.c b/src/plugins/prng/plugin_prng.c
new file mode 100644 (file)
index 0000000..3282788
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * plugin_prng.c
+ *
+ */
+#include <plugin_manager.h>
+#include "plugin_prng.h"
+
+krb5_error_code
+plugin_prng_seed(plhandle handle, krb5_context context, unsigned int randsource,
+                          const krb5_data *data)
+{
+    plugin_prng* api = (plugin_prng*) handle.api;
+    api->prng_seed(context, randsource, data);
+    return 0;
+}
+
+krb5_error_code
+plugin_prng_os_seed(plhandle handle, krb5_context context, int strong, int *success)
+{
+    plugin_prng* api = (plugin_prng*) handle.api;
+    api->prng_os_seed(context, strong, success);
+    return 0;
+}
+
+krb5_error_code
+plugin_prng_rand(plhandle handle, krb5_context context, krb5_data *data)
+{
+    plugin_prng* api = (plugin_prng*) handle.api;
+    api->prng_rand(context, data);
+    return 0;
+}
+
+krb5_error_code
+plugin_prng_init(plhandle handle)
+{
+    plugin_prng* api = (plugin_prng*) handle.api;
+    api->prng_init();
+    return 0;
+}
+
+void
+plugin_prng_cleanup(plhandle handle)
+{
+    plugin_prng* api = (plugin_prng*) handle.api;
+    api->prng_cleanup();
+    return 0;
+}
diff --git a/src/plugins/prng/plugin_prng.h b/src/plugins/prng/plugin_prng.h
new file mode 100644 (file)
index 0000000..86099c6
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * plugin_prng.h
+ *
+ */
+
+#ifndef PLUGIN_PRNG_H_
+#define PLUGIN_PRNG_H_
+
+#include <plugin_manager.h>
+#include <k5-int.h>
+
+/* PRNG API */
+typedef struct {
+       int version;
+       krb5_error_code (*prng_seed)(krb5_context, unsigned int, const krb5_data*);
+       krb5_error_code (*prng_os_seed)(krb5_context, int, int*);
+       krb5_error_code (*prng_rand)(krb5_context, krb5_data*);
+       krb5_error_code (*prng_init)(void);
+       void (*prng_cleanup)(void);
+} plugin_prng;
+
+/* Utility functions */
+krb5_error_code plugin_prng_seed(plhandle handle, krb5_context context, unsigned int randsource,
+                          const krb5_data *data); 
+krb5_error_code plugin_prng_os_seed(plhandle handle, krb5_context context, int strong, int *success);
+krb5_error_code plugin_prng_rand(plhandle handle, krb5_context context, krb5_data *data);
+
+krb5_error_code plugin_prng_init(plhandle handle);
+void plugin_prng_cleanup(plhandle handle);
+
+#endif /* PLUGIN_PRNG_H_ */
diff --git a/src/plugins/prng/plugin_prng_os/Makefile.in b/src/plugins/prng/plugin_prng_os/Makefile.in
new file mode 100644 (file)
index 0000000..90dc313
--- /dev/null
@@ -0,0 +1,36 @@
+mydir=plugins/prng/plugin_prng_os
+BUILDTOP=$(REL)../../..
+KRB5_RUN_ENV = @KRB5_RUN_ENV@
+KRB5_CONFIG_SETUP =
+PROG_LIBPATH=-L$(TOPLIBD)
+PROG_RPATH=$(KRB5_LIBDIR)
+MODULE_INSTALL_DIR = 
+DEFS=@DEFS@
+
+LOCALINCLUDES = -I../../../include/krb5 -I. -I../../../plugin_core -I..
+
+LIBBASE=plugin_prng_os
+LIBMAJOR=0
+LIBMINOR=0
+
+SO_EXT=.so
+
+SHLIB_DIRS=-L$(TOPLIBD)
+SHLIB_RDIRS=$(KRB5_LIBDIR)
+STOBJLISTS=OBJS.ST
+
+STLIBOBJS=  plugin_prng_impl.o  
+
+SRCS=  plugin_prng_impl.c
+
+all-unix:: all-liblinks
+#all-unix:: all-libobjs
+install-unix:: install-libs
+clean-unix:: clean-libs clean-libobjs
+
+clean::
+       $(RM) lib$(LIBBASE)$(SO_EXT)
+
+@libnover_frag@
+@libobj_frag@
+
diff --git a/src/plugins/prng/plugin_prng_os/deps b/src/plugins/prng/plugin_prng_os/deps
new file mode 100644 (file)
index 0000000..9c9fb9f
--- /dev/null
@@ -0,0 +1,5 @@
+plugin_prng_impl.so plugin_prng_impl.po $(OUTPRE)plugin_prng_impl.$(OBJEXT): \
+  $(BUILDTOP)/include/krb5/krb5.h $(COM_ERR_DEPS) $(top_srcdir)/plugins/prng/os/plugin_prng_impl.h \
+  $(top_srcdir)/plugin_core/plugin_manager.h \
+  $(top_srcdir)/plugin_core/plugin_factory.h \
+  plugin_prng_impl.c
diff --git a/src/plugins/prng/plugin_prng_os/os.exports b/src/plugins/prng/plugin_prng_os/os.exports
new file mode 100644 (file)
index 0000000..af32fd1
--- /dev/null
@@ -0,0 +1 @@
+plugin_simple_prng_create
diff --git a/src/plugins/prng/plugin_prng_os/plugin_prng_impl.c b/src/plugins/prng/plugin_prng_os/plugin_prng_impl.c
new file mode 100644 (file)
index 0000000..b6a3a2a
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * plugins.c
+ *
+ */
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include "plugin_prng.h"
+
+static krb5_error_code
+_plugin_prng_os_seed(krb5_context context, int strong, int *success)
+{
+    return 0;
+}
+static krb5_error_code
+_plugin_prng_seed(krb5_context context, unsigned int randsource,
+                          const krb5_data *data)
+{
+    long seed = (long)data->data;
+       printf("seeding prng...\n");
+       srand(seed);
+    return 0;
+}
+
+static krb5_error_code
+_plugin_prng_rand(krb5_context context, krb5_data *data)
+{
+       int number = rand();
+       printf("generating random number...\n");
+        memcpy(data->data, &number, data->length);
+       return 0;
+}
+
+static void
+_plugin_prng_cleanup(plugin_prng* api)
+{
+    return;
+/*     if (api != NULL) {
+               free(api);
+       }
+*/
+}
+
+static krb5_error_code
+_plugin_prng_init(void)
+{
+     return 0;
+}
+
+
+plhandle 
+plugin_simple_prng_create()
+{
+       plhandle handle;
+       plugin_prng* api = malloc(sizeof(plugin_prng));
+
+       memset(api, 0, sizeof(plugin_prng));
+       api->version = 0;
+       api->prng_rand = _plugin_prng_rand;
+       api->prng_seed = _plugin_prng_seed;
+        api->prng_os_seed = _plugin_prng_os_seed;
+        api->prng_init = _plugin_prng_init;
+        api->prng_cleanup = _plugin_prng_cleanup;
+       handle.api = api;
+
+       return handle;
+}
diff --git a/src/plugins/prng/plugin_prng_os/plugin_prng_impl.h b/src/plugins/prng/plugin_prng_os/plugin_prng_impl.h
new file mode 100644 (file)
index 0000000..427f3a1
--- /dev/null
@@ -0,0 +1,14 @@
+/*
+ * plugin_prng_impl.h
+ *
+ */
+
+#ifndef PLUGIN_PRNG_IMPL_H_
+#define PLUGIN_PRNG_IMPL_H_
+
+#include <plugin_manager.h>
+#include <plugin_prng.h>
+
+plhandle plugin_simple_prng_create();
+
+#endif /* PLUGIN_PRNG_IMPL_H_ */
diff --git a/src/plugins/prng/plugin_yarrow/Makefile.in b/src/plugins/prng/plugin_yarrow/Makefile.in
new file mode 100644 (file)
index 0000000..c8ea15a
--- /dev/null
@@ -0,0 +1,34 @@
+mydir=plugins/prng/plugin_yarrow
+BUILDTOP=$(REL)../../..
+PROG_LIBPATH=-L$(TOPLIBD)
+PROG_RPATH=$(KRB5_LIBDIR)
+DEFS=
+
+LOCALINCLUDES = -I../../../include/krb5 -I. -I../../../plugin_core -I..  -I$(srcdir)/.. \
+               -I$(srcdir)/../../../lib/crypto/@CRYPTO_IMPL@         \
+               -I$(srcdir)/../../../lib/crypto/@CRYPTO_IMPL@/sha1    \
+               -I$(srcdir)/../../../lib/crypto/@CRYPTO_IMPL@/enc_provider
+
+
+
+STLIBOBJS=\
+       yarrow.o \
+       ycipher.o \
+       plugin_prng_impl.o
+
+OBJS=\
+       $(OUTPRE)yarrow.$(OBJEXT) \
+       $(OUTPRE)ycipher.$(OBJEXT) \
+       $(OUTPRE)plugin_prng_impl.$(OBJEXT)
+
+SRCS=\
+       $(srcdir)/yarrow.c \
+       $(srcdir)/ycipher.c \
+       $(srcdir)/plugin_prng_impl.c
+
+all-unix:: all-libobjs
+
+depend:: $(SRCS)
+clean-unix:: clean-libobjs
+
+@libobj_frag@
similarity index 73%
rename from src/lib/crypto/krb/yarrow/deps
rename to src/plugins/prng/plugin_yarrow/deps
index 9387393329433a5f19c019ea61d1ede405c1b38f..da07f984522e85114eec42c33ec1bf76e0abdf89 100644 (file)
@@ -3,8 +3,8 @@
 #
 yarrow.so yarrow.po $(OUTPRE)yarrow.$(OBJEXT): $(BUILDTOP)/include/autoconf.h \
   $(BUILDTOP)/include/krb5/krb5.h $(BUILDTOP)/include/osconf.h \
-  $(BUILDTOP)/include/profile.h $(COM_ERR_DEPS) $(srcdir)/../../builtin/sha1/shs.h \
-  $(srcdir)/../../builtin/yhash.h $(top_srcdir)/include/k5-buf.h \
+  $(BUILDTOP)/include/profile.h $(COM_ERR_DEPS) $(srcdir)/../../../lib/crypto/builtin/sha1/shs.h \
+  $(srcdir)/../../../lib/crypto/builtin/yhash.h $(top_srcdir)/include/k5-buf.h \
   $(top_srcdir)/include/k5-err.h $(top_srcdir)/include/k5-gmt_mktime.h \
   $(top_srcdir)/include/k5-int-pkinit.h $(top_srcdir)/include/k5-int.h \
   $(top_srcdir)/include/k5-platform.h $(top_srcdir)/include/k5-plugin.h \
@@ -15,8 +15,8 @@ yarrow.so yarrow.po $(OUTPRE)yarrow.$(OBJEXT): $(BUILDTOP)/include/autoconf.h \
   ycipher.h yexcep.h ylock.h ystate.h ytypes.h
 ycipher.so ycipher.po $(OUTPRE)ycipher.$(OBJEXT): $(BUILDTOP)/include/autoconf.h \
   $(BUILDTOP)/include/krb5/krb5.h $(BUILDTOP)/include/osconf.h \
-  $(BUILDTOP)/include/profile.h $(COM_ERR_DEPS) $(srcdir)/../../builtin/enc_provider/enc_provider.h \
-  $(srcdir)/../../builtin/sha1/shs.h $(srcdir)/../../builtin/yhash.h \
+  $(BUILDTOP)/include/profile.h $(COM_ERR_DEPS) $(srcdir)/../../../lib/crypto/builtin/enc_provider/enc_provider.h \
+  $(srcdir)/../../../lib/crypto/builtin/sha1/shs.h $(srcdir)/../../../lib/crypto/builtin/yhash.h \
   $(top_srcdir)/include/k5-buf.h $(top_srcdir)/include/k5-err.h \
   $(top_srcdir)/include/k5-gmt_mktime.h $(top_srcdir)/include/k5-int-pkinit.h \
   $(top_srcdir)/include/k5-int.h $(top_srcdir)/include/k5-platform.h \
@@ -25,3 +25,9 @@ ycipher.so ycipher.po $(OUTPRE)ycipher.$(OBJEXT): $(BUILDTOP)/include/autoconf.h
   $(top_srcdir)/include/krb5/locate_plugin.h $(top_srcdir)/include/krb5/preauth_plugin.h \
   $(top_srcdir)/include/port-sockets.h $(top_srcdir)/include/socket-utils.h \
   yarrow.h ycipher.c ycipher.h ytypes.h
+plugin_prng_impl.so plugin_prng_impl.po $(OUTPRE)plugin_prng_impl.$(OBJEXT): \
+  $(BUILDTOP)/include/krb5/krb5.h $(COM_ERR_DEPS) $(top_srcdir)/plugins/prng/plugin_yarrow/plugin_prng_impl.h \
+  $(top_srcdir)/plugin_core/plugin_manager.h \
+  $(top_srcdir)/plugin_core/plugin_factory.h \
+  plugin_prng_impl.c
+
diff --git a/src/plugins/prng/prng.exports b/src/plugins/prng/prng.exports
new file mode 100644 (file)
index 0000000..49943ce
--- /dev/null
@@ -0,0 +1,5 @@
+plugin_prng_seed
+plugin_prng_os_seed
+plugin_prng_rand
+plugin_prng_init
+plugin_prng_cleanup